#!/bin/sh # DWIM cvs/svn/whatever wrapper. # (public domain) 2008, 2009 Christoph Berg # One of the scripts I should have written years ago. try_vcs_dir () { dir="$1" #echo "Looking in $dir ..." if [ -d $dir/.svn ] ; then VCS=svn elif [ -d $dir/.hg ] ; then VCS=hg elif [ -d $dir/.git ] ; then VCS=git elif [ -d $dir/.bzr ] ; then VCS=bzr elif [ -d $dir/CVS ] ; then VCS=cvs else return 1 fi return 0 } find_vcs () { base="$1" #echo "Looking from $base ..." if try_vcs_dir $base || try_vcs_dir $base/.. || try_vcs_dir $base/../.. || try_vcs_dir $base/../../.. ; then echo "$VCS: $dir" 1>&2 return 0 fi echo "No VCS found" 1>&2 exit 1 } command="$1" test "$command" && shift for base in "$@" ; do : ; done test -d "$base" || base="$(dirname -- "$base")" test -d "$base" || base="." find_vcs "$base" 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|com|commit) case $VCS in bzr) bzr $command "$@" && bzr push ;; hg) hg $command "$@" && hg push ;; git) git ci "$@" && { read -p "Push? y:yes r:pull --rebase and push [y] " push case $push in "") git push ;; y|p) git push ;; r) git pull --stat --rebase && git 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) case $VCS in cvs) cvs update "$@" ;; *) $VCS $command "$@" ;; esac ;; up|update) case $VCS in bzr) bzr pull "$@" ;; hg) hg pull -u "$@" ;; git) git pull "$@" ;; *) $VCS $command "$@" ;; esac ;; add|co|cp|info|log|mv|resolved|revert|rm|"") $VCS $command "$@" ;; *) echo "$0: $VCS command '$command' not recognized. YMMV." 1>&2 $VCS "$command" "$@" ;; esac