forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-rdiff
executable file
·73 lines (63 loc) · 1.77 KB
/
git-rdiff
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
#!/bin/bash -e
## Show diff branch..origin/branch
## for this repository and all submodules
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Recursive diff
This command compares local with remote branches recursively for
each submodule and lists differing files.
Usage:
git rdiff
EOF
exit 0;
fi
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
## ensure we are in the toplevel directory
cdup=$(git rev-parse --show-toplevel) &&
cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1
}
## continue silently, if there are unstaged changes
## we assume that such directories have already been merged.
## TODO: also show difference if fast forward is possible.
## TODO: if differences in submodules, show nicer output
if git check-clean --unstaged --unmerged --exit-code --ignore-submodules=dirty; then
## check if its a remote tracking branch and get it
tmp=`git branch --no-color -vv 2> /dev/null`
while read line; do
if [[ "${line:0:1}" != "*" ]]; then
continue
fi
##echo "$line"
branch=`expr "$line" : '\** *\([^ ]*\)'`
remote=`expr "$line" : '.*\[\(.*\)\]'` || nontracking=0
remote=`expr "$remote" : '\([^:]*\)'`
done <<< "$tmp"
if [[ "$nontracking" ]]; then
cat >&2 <<EOF
Error in $PWD:
Not on a remote tracking branch.
EOF
else
output=`git diff $branch..$remote --ignore-submodules --stat --no-ext-diff`
if [[ "$output" != "" ]]; then
cat<<EOF
Diff in $PWD:
$output
EOF
fi
fi
fi
## check for differences in submodules
if [ -f .gitmodules ]; then
#git submodule --quiet foreach git rdiff
git submodule --quiet foreach 'echo "$toplevel/$path"' |
xargs -r -n1 -P5 bash -c 'cd "$1"; git rdiff' xargs
fi