Created
July 28, 2009 19:29
-
-
Save smathy/157615 to your computer and use it in GitHub Desktop.
Bash functions for svn
This file contains hidden or 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/bash | |
alias inf=svn\ info | |
alias ci=svn\ ci | |
alias up=svn\ up | |
alias st=svn\ st | |
export RRAKE=`which rake` | |
export MM="rake test:units" | |
root='https://wush.net/svn/ese/see' | |
m() { | |
if [[ "$1" == "" ]]; then | |
if [[ "$MM" == "" ]]; then | |
$RRAKE test:units | |
else | |
$MM | |
fi | |
else | |
sub='unit' | |
t=$1 | |
e="$2 $3" | |
if [[ "$1" == "-f" ]]; then | |
sub='functional' | |
t="${2}_controller" | |
e="$3 $4" | |
fi | |
export MM="ruby -Ilib:test test/${sub}/${t}_test.rb $e" | |
m | |
fi | |
unset sub t e | |
} | |
r() { | |
if [[ "$1" == "" ]]; then | |
$RRAKE $RLAST | |
else | |
RLAST=$1 | |
$RRAKE $* | |
fi | |
} | |
get_url() { | |
if [[ "$branch" == "" ]]; then | |
target='' | |
else | |
target="branches/$branch" | |
svn info $root/$target >/dev/null 2>&1 | |
if [ $? -gt 0 ]; then | |
target="tags/$branch" | |
svn info $root/$target >/dev/null 2>&1 | |
if [ $? -gt 0 ]; then | |
target='' | |
return 1 | |
fi | |
fi | |
fi | |
} | |
log() { | |
days='3' | |
soc='--stop-on-copy' | |
verbose='' | |
while getopts fvd: OPT; do | |
case "$OPT" in | |
d) days=$OPTARG | |
;; | |
f) soc='' | |
;; | |
v) verbose='-v' | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
target='' | |
if [[ "$1" != "" ]]; then | |
branch=$1 | |
get_url | |
fi | |
url='' | |
if [[ "$target" == "" ]]; then | |
url=$1 | |
else | |
url="$root/$target" | |
fi | |
date=`gdate --date="$days days ago" +%Y-%m-%d` | |
svn log -r{$date}:HEAD $verbose $soc $url | |
echo $'\e[1;32m'Log $target since $date$'\e[0m' | |
unset OPTSTRING OPTIND OPTARG OPT days soc verbose target date url | |
} | |
sw() { | |
branch=$1 | |
target='' | |
get_url | |
if [[ "$target" == "" ]]; then | |
target='trunk' | |
fi | |
svn sw $root/$target | |
if [ $? == 0 ]; then | |
echo $'\e[1;32m'Switched to $target$'\e[0m' | |
fi | |
unset branch target | |
} | |
br() { | |
sub='branches' | |
while getopts tld:r: OPT; do | |
case "$OPT" in | |
t) sub='tags' | |
;; | |
r|d) leaf=$OPTARG | |
remove='1' | |
;; | |
l) list='1' | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
if [[ "$remove" == "1" ]]; then | |
svn rm $root/$sub/$leaf -m"Removing $leaf from $sub" | |
if [ $? == 0 ]; then | |
echo $'\e[32m'Removed $leaf from $sub$'\e[0m' | |
else | |
echo $'\e[31m'Failed to remove $leaf from $sub$'\e[0m' | |
fi | |
elif [[ "$list" == "1" || "$1" == "" ]]; then | |
svn ls $root/$sub | |
else | |
leaf=$1 | |
svn cp $root/trunk $root/$sub/$leaf -m"Branching trunk to $sub/$leaf" | |
if [ $? == 0 ]; then | |
svn sw $root/$sub/$leaf | |
if [ $? == 0 ]; then | |
echo $'\e[1;32m'Switched to $sub/$leaf$'\e[0m' | |
fi | |
fi | |
fi | |
unset OPTSTRING OPTIND OPTARG OPT leaf sub list remove | |
} | |
mg() { | |
command="merge" | |
msg='Merging' | |
while getopts lir:c: OPT; do | |
case "$OPT" in | |
i) opts="$opts --reintegrate" | |
;; | |
l) command="mergeinfo --show-revs eligible" | |
msg="Eligibles for" | |
;; | |
r) opts="$opts -r$OPTARG" | |
;; | |
c) opts="$opts -c$OPTARG" | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
if [[ "$1" == "" || "$1" == "trunk" ]]; then | |
# no arg so assume a trunk merge | |
echo $'\e[1;32m'$msg trunk$'\e[0m' | |
svn $command $opts $root/trunk . | |
else | |
branch=$1 | |
get_url | |
echo $'\e[1;32m'$msg $target$'\e[0m' | |
svn $command $opts $root/$target . | |
fi | |
unset OPTSTRING OPTIND OPTARG OPT opts command msg branch target | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment