Add svnsafeup function to svn plugin.

This provides a useful method to update some SVN repository in a "safely"
manner.
This commit is contained in:
Daniel Hahler 2011-03-23 21:27:55 +01:00
commit cef8ea75a9

View file

@ -39,4 +39,45 @@ function svn_dirty_choose {
function svn_dirty {
svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
}
}
# Function to update an SVN repository in a safe manner: first display
# diffstat (if installed), log and diff, then ask about continuing with
# `svn up`.
# Optional args: $to $from (default: HEAD BASE)
function svnsafeup() {
if [[ "$(in_svn)" != "1" ]]; then
echo "Not in a SVN repository." 1>&2 ; return 1
fi
local from=${2:-BASE} to=${1:-HEAD}
local range="$from:$to"
local marker_o='{{{' marker_c="}}}\n\n" # fold markers
local repo_id="$(svn_get_repo_name)@$(svn_get_rev_nr)"
local diffcmd="svn diff -r $range"
local diff=$($=diffcmd)
if [[ $diff == '' ]] ; then
echo "No changes for $repo_id in range $range."
return
fi
{
echo "Diff for: $repo_id, range: $range"
echo
if [ $commands[diffstat] ] ; then
echo "$diffcmd | diffstat: $marker_o"
echo $diff | diffstat
echo "$marker_c"
fi
echo "svn log -r $range: $marker_o"
svn log -r $range
echo "$marker_c"
echo "$diffcmd: $marker_o"
echo $diff
echo "$marker_c"
# add modeline for vim
echo " vim:fdm=marker:fdl=1:"
} | view -
read "?continue to 'svn up'? (ctrl-c to abort)" || return 1
svn up -r $to
}