summaryrefslogtreecommitdiff
path: root/scripts/utils
blob: c096f29f882755b5cfaea7d5f657dceaac9e5913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# vim: ft=sh

# Simple echo wrapper for stage marking
echo_stage() {
	echo -e "\033[1;34m========== $@ ==========\033[0m"
}

# Simple echo wrapper for stage marking
echo_info() {
	echo -e "\033[1;32m---------- $@ ----------\033[0m"
}

# Fetch bare git repository to WORKSPACE
# First argument has to be a source URL
# Second argument is name of directory to which will be repository cloned to.
git_fetch_bare() {
	if [ -d "$WORKSPACE/$2" ]; then
		git --git-dir="$WORKSPACE/$2" --bare remote update --prune
	else
		git clone --mirror "$1" "$WORKSPACE/$2"
	fi
}

# Calls git_fetch_bare and then creates detached work tree in run directory
# First agument has to be a source URL
# Second argument is name of directory to which will be directory cloned in.
# Second argument is optional and should be branch name (master is used if not
# provided).
git_fetch() {
	git_fetch_bare "$1" "$2"
	local BRANCH="$3"
	[ -n "$BRANCH" ] || BRANCH=master
	git --git-dir="$WORKSPACE/$2" --bare worktree add --detach $2 $BRANCH
}

# Lock special lock for this job
# Extension appended to lock name has to be provided as first argument
laminar_self_lock() {
	# TODO trap release
	laminarc lock "$(basename "$0")-$1"
}

# Unlock special lock for this job
# Extension appended to lock name has to be provided as first argument
laminar_self_unlock() {
	# TODO remove trap release
	laminarc unlock "$(basename "$0")-$1"
}