Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created January 8, 2012 22:58
Show Gist options
  • Save mgedmin/1580021 to your computer and use it in GitHub Desktop.
Save mgedmin/1580021 to your computer and use it in GitHub Desktop.
Find all svn/bzr/git/hg checkouts under ~/src and see if any have uncommitted changes.
#!/bin/bash
verbose=0
unknown=0
svn=0
bzr=0
git=0
hg=0
for arg in "$@"; do
case "$arg" in
-h|--help)
echo "Usage: $0 [-v|--verbose] [--svn|--bzr|--git|--hg] [...]"
echo
echo "Find all checkouts under ~/src and see if any have uncommitted changes."
echo
echo "Options:"
echo " -v, --verbose be more verbose"
echo " -u, --unknown show unknown (untracked) files "
echo " --svn check only svn checkouts"
echo " --bzr check only bzr checkouts"
echo " --git check only git checkouts"
echo " --hg check only hg checkouts"
exit 0
;;
-v|--verbose)
verbose=1
;;
-u|--unknown)
unknown=1
;;
--svn)
svn=1
;;
--bzr)
bzr=1
;;
--git)
git=1
;;
--hg)
hg=1
;;
-*)
echo "$0: unsupported option: $arg" 1>&2
exit 1
;;
*)
echo "$0: extra argument: $arg" 1>&2
exit 1
;;
esac
done
if [ $svn -eq 0 -a $bzr -eq 0 -a $git -eq 0 -a $hg -eq 0 ]; then
svn=1
bzr=1
git=1
hg=1
fi
# svn st without useless junk about externals and whatnot, sorted sanely
test -t 1 && {
hi='\033[1m'
black='\033[30m'
red='\033[31m'
green='\033[32m'
orange='\033[33m'
blue='\033[34m'
purple='\033[35m'
cyan='\033[36m'
white='\033[37m'
reset='\033[0m'
}
for i in ~/src/*; do
output=""
type=""
test $svn -ne 0 -a -d "$i/.svn" && {
type=svn
# our --verbose has no effect for svn; not sure what it could show
if [ $unknown -ne 0 ]; then
output=$(svn st "$i"|grep -v '^X\|^Performing\|^ L\|^$'|LC_COLLATE=C sort)
else
output=$(svn st "$i"|grep -v '^[X?]\|^Performing\|^ L\|^$'|LC_COLLATE=C sort)
fi
}
test $bzr -ne 0 -a -d "$i/.bzr" && {
type=bzr
args="-S"
test $unknown -eq 0 && args="$args -V"
test $verbose -ne 0 && args="$args -v"
# -v doesn't seem to be doing much: it shows detailed pending merge info
# use --no-plugins to avoid bzr-svn slowness
output=$(bzr --no-plugins st $args "$i" 2>&1)
}
test $git -ne 0 -a -d "$i/.git" && {
type=git
args="-uno"
test $unknown -ne 0 && args=
if [ $verbose -ne 0 ]; then
output=$(cd "$i" && git status $args | grep -v '^nothing to commit (use -u to show untracked files)$\|^# On branch .*$\|^# *$')
else
output=$(cd "$i" && git status $args -s)
fi
}
test $hg -ne 0 -a -d "$i/.hg" && {
type=hg
args=""
test $unknown -eq 0 && args="$args -q"
# our --verbose has no effect for hg; not sure what it could show
output=$(cd "$i" && hg status $args)
}
test -n "$output" && \
printf "$green+ %s$reset $orange[$type]$reset\n%s\n" \
"$i" "$output"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment