From 7cc083958267b3b438b294a448eab0f0bdb69610 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 18 Apr 2014 16:31:23 -0700 Subject: [PATCH] add git_diff_replacing function --- dotfiles/lib/shellrc/functions.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dotfiles/lib/shellrc/functions.sh b/dotfiles/lib/shellrc/functions.sh index cffae2d7..0c2d4b19 100644 --- a/dotfiles/lib/shellrc/functions.sh +++ b/dotfiles/lib/shellrc/functions.sh @@ -101,3 +101,27 @@ function clipboard() { function git_root() { cd `git root` } + +function git_diff_replacing() { + local original_sha='HEAD~1' + local new_sha='HEAD' + while getopts "do:n:" OPTCHAR; do; + case $OPTCHAR in + o) + original_sha="$OPTARG" + ;; + n) + new_sha="$OPTARG" + ;; + d) + debug="true" + esac + done + shift $((OPTIND-1)) + local replaced="$1" + local replacing="$2" + local replace_sha_string='$(echo filename | sed '"s:$replaced:$replacing:g"')' + test -z $debug || echo "Diffing from $original_sha to $new_sha, replacing $replaced with $replacing" + test -z $debug || git diff $original_sha $new_sha --name-only | grep -v "$replacing" + git diff $original_sha $new_sha --name-only | grep -v "$replacing" | xargs -I filename sh -c "git diff $original_sha:filename $new_sha:"$replace_sha_string +}