-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.lib.sh
executable file
·83 lines (70 loc) · 2.14 KB
/
git.lib.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
################################################################################
# git.lib.sh - Bash library functions related to Git
################################################################################
#
# Copyright (C) 2014 stepping stone GmbH
# Bern, Switzerland
# http://www.stepping-stone.ch
#
# Authors:
# Christian Affolter <[email protected]>
#
# Licensed under the EUPL, Version 1.1.
#
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
################################################################################
# The path to the lib directory.
# The default value only works if not sourced or executed from within $PATH
LIB_DIR=${LIB_DIR:="$(readlink -f ${0%/*})"}
source "${LIB_DIR}/input-output.lib.sh"
# The path to the git command
GIT_CMD="${GIT_CMD:="/usr/bin/git"}"
test -f "${GIT_CMD}" || die "Missing git command: '${GIT_CMD}'"
# Clones a Git repository into a new directory
#
# Returns the exit status of the git command.
#
# gitCheckoutBranch url directory
function gitCloneRepository ()
{
local gitUrl="$1"
local gitDir="$2"
${GIT_CMD} clone \
"${gitUrl}" \
"${gitDir}" 2> >(info -)
return $?
}
# Checks out a given branch (default master) in a Git working directory
#
# Returns the exit status of the git command.
#
# gitCheckoutBranch directory [branch [track]]
function gitCheckoutBranch ()
{
local workingDir="$1"
local branch="${2:-"master"}"
local track=${3}
if $track; then
track="--track";
else
track=""
fi
${GIT_CMD} -C "${workingDir}" \
checkout ${track} "${branch}" 2> >(info -)
return $?
}