blob: 6d810d73506ba40bad26f777589e8b9f09ebf723 (
plain) (
blame)
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
|
# Defines common function and variables used by the scripts
function git_clone_or_update() {
local url="$1"
local destination="$2"
local branch="$3"
if [[ ! -e "${destination}/.git" ]]; then
git clone $([ "${branch}x" != "x" ] && echo "--depth 1 -b ${branch}" || echo "") "$url" "$destination"
else
cd "$destination"
git pull
if [[ ! -z "$branch" ]]; then
git checkout "${branch}"
fi
fi
}
function get_git_hash() {
local url="$1"
local branch="$2"
local commit_id=""
# List remote git branches and get the commit id of the branch
commit_id="$(git ls-remote -h "$url" |grep "$branch" | cut -d$'\t' -f 1)"
# If that doesn't work use the branch instead of the commit id
if [[ -z "${commit_id}" ]]; then
echo "${branch}"
else
echo "${commit_id:0:7}"
fi
}
|