-
Notifications
You must be signed in to change notification settings - Fork 1
/
gu_tools.inc.sh
51 lines (45 loc) · 1.24 KB
/
gu_tools.inc.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
shopt -s extglob
function asksure() {
echo -n "Are you sure (Y/N)? "
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}
function git_cleaning() {
git fetch --prune > /dev/null 2>&1
git branch -D $(git branch -vv | grep ': gone] ' | awk '{print $1}' | xargs) > /dev/null 2>&1
}
function remote_avail() {
local remote=$1
git remote show $remote >/dev/null 2>&1
CODE=$?
# code 128 means origin does not exist in the repo.
if [ "$CODE" = "128" ]; then
return 1
fi
return 0
}
function origin_avail() {
if remote_avail origin; then return 0; else return 1; fi
}
# Check to see if the branch is on remote origin
# if not then allow to rebase current branch otherwise merge.
function branch_avail_on_remote() {
local remote=$1
local branch=$2
if ! origin_avail; then return 1; fi
git branch -vv | grep -w "$remote/$branch" | grep -v gone >/dev/null 2>&1
#git remote show $remote | grep -w $branch >/dev/null 2>&1
CODE=$?
# code 0 means found branch on remote.
return $CODE
}
if [ -z "${BASED_BRANCH-}" ]; then
export BASED_BRANCH=development
fi