forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-check-non-tracking
executable file
·68 lines (60 loc) · 1.54 KB
/
git-check-non-tracking
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
#!/bin/bash -e
## Check for non-tracking branches not fully merged to HEAD.
## if argument -p is given: does not exit with a failure
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Check for any non-tracking branches
This command checks for non-tracking branches that are not fully
merged to a tracking branch. This is part of a series of checks
used to determine whether it is safe to remove a submodule.
Usage:
git check-non-tracking [-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 -vv --no-color --no-merged 2> /dev/null`
if [[ "$tmp" ]]; then
while read line; do
##echo "$line"
branch=`expr "$line" : '\** *\([^ ]*\)'`
##echo "$branch"
remote=`expr "$line" : '.*\[\(.*\)\]'` && continue
## this might be a a non-tracking branch that is not fully merged to some other tracking branch
if (git branch -vv --no-color --contains testbranch) | grep \\[.*/.*\\] -q; then
continue
else
nontracking="$nontracking $branch is not a remote tracking branch and is not fully merged any tracking branch.
"
fi
done <<< "$tmp"
fi
if [ "$nontracking" ]; then
if [[ $p -ne 1 ]]; then
echo >&2 -n "Error in $PWD:
$nontracking"
exit 1
fi
echo -n "In $PWD:
$nontracking"
fi