From cef8ea75a9db3c483cd5d93a07e61ff810ec7816 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 23 Mar 2011 21:27:55 +0100 Subject: [PATCH] Add svnsafeup function to svn plugin. This provides a useful method to update some SVN repository in a "safely" manner. --- plugins/svn/svn.plugin.zsh | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/svn/svn.plugin.zsh b/plugins/svn/svn.plugin.zsh index 45d461306..062b7123c 100644 --- a/plugins/svn/svn.plugin.zsh +++ b/plugins/svn/svn.plugin.zsh @@ -39,4 +39,45 @@ function svn_dirty_choose { function svn_dirty { svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN -} \ No newline at end of file +} + +# 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 +}