Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 67 lines (57 sloc) 1.68 KB
#!/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
## 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