forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-check-branch
executable file
·67 lines (59 loc) · 1.6 KB
/
git-check-branch
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
#!/bin/bash -e
## Check if we're on a remote tracking branch
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Check for a remote tracking branch
This command checks whether the repository is on a remote tracking
branch. Otherwise an error is raised.
Does not raise an error if the repository is in detached HEAD mode
and there are no new commits.
Usage:
git check-branch
EOF
exit 0;
fi
if !(git symbolic-ref -q HEAD > /dev/null) ; then
## detached head cannot be remote tracking branch...
## ...but: if there are no new commits, we can safely ignore this
## FIXME: this test only succeed if the new commit is actually
## checked out
if !(git diff origin... --quiet) ; then
cat >&2 <<EOF
Error in $PWD:
Detached head and new commits. Attach the HEAD by creating
a new branch or risk losing the commits.
EOF
exit 1
fi
cat >&2 <<EOF
Warning in $PWD:
Detached head. This probably just mean that there are updates available
that are not yet used. To update to the most recent version, use
git attach-head -w
EOF
exit 0
fi
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
tmp=`git branch --no-color -vv 2> /dev/null`
while read line; do
if [[ "${line:0:1}" != "*" ]]; then
continue
fi
#echo "$line"
remote=`expr "$line" : '.*\[\(.*\)\]'` || nontracking=0
done <<< "$tmp"
activebranch=`git name-rev --name-only HEAD`
if [[ "$nontracking" ]]; then
## if we're here: fail
cat >&2 <<EOF
Error in $PWD:
Branch "$activebranch" is not a remote tracking branch.
EOF
exit 1
fi