Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dotfiles/bin/v
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
143 lines (136 sloc)
3.4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
set -eu | |
try_vcs_dir () | |
{ | |
dir="$1" | |
#echo "Looking in $dir ..." | |
if [ -d $dir/.git ] ; then | |
VCS=git | |
if grep -q ChristophBerg $dir/.git/config; then | |
sed -i -e 's/ChristophBerg/df7cb/g' $dir/.git/config | |
fi | |
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 --prune "$@" | |
# fast-forward Debian packaging branches | |
current_branch=$(git symbolic-ref --short HEAD) | |
for branch in master experimental upstream debian/upstream pristine-lfs pristine-tar; do | |
[ "$branch" = "$current_branch" ] && continue # skip currently checked out branch | |
origin=$(git rev-parse --verify origin/$branch 2> /dev/null) || continue | |
mine=$(git rev-parse --verify $branch 2> /dev/null || :) # branch might not exist yet | |
if [ "$mine" != "$origin" ]; then | |
if [ -z "$mine" ] || git merge-base --is-ancestor $mine $origin; then | |
echo "+ Updating $branch $mine..$origin" | |
git update-ref refs/heads/$branch $origin $mine | |
elif git merge-base --is-ancestor $origin $mine; then | |
echo "+ $branch is ahead of origin/$branch" | |
else | |
echo "+ $branch cannot be fast-forwarded" | |
exit 1 | |
fi | |
else | |
echo "+ $branch is up-to-date" | |
fi | |
done | |
;; | |
*) $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 |