forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-check-unpushed
executable file
·65 lines (57 loc) · 1.39 KB
/
git-check-unpushed
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
#!/bin/bash -e
## Check for unpushed commits in remote tracking branches
## if argument -p is given: does not exit with a failure
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Check for unpushed commits in tracking branches
This command checks for unpushed commits in tracking branches.
This is part of a series of checks used to determine whether it is
safe to remove a submodule.
Usage:
git check-unpushed [-p]
-p: do not raise an error
EOF
exit 0;
fi
while getopts ":p" opt; do
case $opt in
p)
p=1
#echo "-p was triggered!" >&2
;;
\?)
# ignore this
#echo "Invalid option: -$OPTARG" >&2
;;
esac
done
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
## cycle all branches
tmp=`git branch --no-color -vv 2> /dev/null`
while read line; do
##echo "$line"
branch=`expr "$line" : '\** *\([^ ]*\)'`
##echo "$branch"
remote=`expr "$line" : '.*\[\(.*\)\]'` || continue
##echo "$remote"
## if we're ahead: branch will show it after ":"
status=`expr "$remote" : '.*: ahead \(.*\)'` || continue
##echo "$status"
unpushed="$unpushed Branch \"$branch\" is ahead $status commit(s).
"
done <<< "$tmp"
if [ "$unpushed" ]; then
if [[ $p -ne 1 ]]; then
echo >&2 -n "Error in $PWD:
$unpushed"
exit 1
fi
echo -n " In $PWD:
$unpushed"
fi