Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 117 lines (110 sloc) 2.42 KB
#!/bin/sh
# DWIM cvs/svn/whatever wrapper.
# (public domain) 2008, 2009 Christoph Berg <cb@df7cb.de>
# One of the scripts I should have written years ago.
try_vcs_dir ()
{
dir="$1"
#echo "Looking in $dir ..."
if [ -d $dir/.git ] ; then
VCS=git
elif [ -d $dir/.svn ] ; then
VCS=svn
elif [ -d $dir/.hg ] ; then
VCS=hg
elif [ -d $dir/.bzr ] ; then
VCS=bzr
elif [ -d $dir/CVS ] ; then
VCS=cvs
else
return 1
fi
return 0
}
find_vcs ()
{
for dir in . .. ../.. ../../.. ../../../.. ../../../../..; do
if try_vcs_dir $dir; then
#echo "Found $VCS in $dir"
return 0
fi
done
echo "No VCS found" 1>&2
exit 1
}
b=$(basename $0)
case $b in
v)
command="$1"
test "$command" && shift
;;
*)
command="$b"
;;
esac
find_vcs
case $command in
br|branch) $VCS branch "$@" ;;
cdi|cdiff) case $VCS in
git) GIT_EXTERNAL_DIFF=git-context-diff git diff "$@" ;;
*) echo "Not supported yet" >&2 ;;
esac ;;
ci|cia|com|commit) case $VCS in
bzr) $VCS $command "$@" && {
read -p "Push? y:yes [y] " push
case $push in
"") $VCS push ;;
y|p) $VCS push ;;
esac
} ;;
hg) hg $command "$@" && hg push ;;
git) $VCS $command "$@" && {
read -p "Push? y:yes r:pull --rebase and push [y] " push
case $push in
"") $VCS push ;;
y|p) $VCS push ;;
r) $VCS pull --stat --rebase && $VCS push ;;
esac
} ;;
*) $VCS $command "$@" ;;
esac ;;
di|diff) if [ "$VCS" != git ] && [ -t 1 ] && [ -x /usr/bin/colordiff ] ; then
$VCS $command "$@" | colordiff
else
$VCS $command "$@"
fi ;;
wd|wdi|wdiff) case $VCS in
git) git diff --color-words "$@" ;;
svn) svn diff --diff-cmd wdiff.sh "$@" ;;
*) $VCS diff "$@" | wdiff -d ;;
esac ;;
pull) case $VCS in
hg) hg pull -u "$@" ;;
svn) [ "$1" = "-u" ] && shift
svn update "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
push) case $VCS in
#git) $VCS $command "$@" && git push --tags ;;
*) $VCS $command "$@" ;;
esac ;;
revert) case $VCS in
git) $VCS co -- "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
st|status|sti) case $VCS in
cvs) cvs update "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
# default action
up|update|"") case $VCS in
bzr) bzr pull "$@" ;;
hg) hg pull -u "$@" ;;
git) git pull "$@" && git remote prune origin ;;
*) $VCS update "$@" ;;
esac ;;
add|blame|co|cp|info|log|mv|resolved|revert|rm)
$VCS $command "$@" ;;
*) #echo "$0: $VCS command '$command' not recognized. YMMV." 1>&2
$VCS "$command" "$@" ;;
esac