-
-
Save galak-fyyar/7e9aa29a2ed7c7a2f5b1 to your computer and use it in GitHub Desktop.
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 | |
set -e | |
#receipt http://stackoverflow.com/questions/14062895/bash-argument-case-for-args-in/14063511#14063511 | |
while [[ $# -gt 0 ]] && [[ ."$1" = .--* ]]; do | |
optname="$1"; | |
shift; #expose next argument | |
case "$optname" in | |
"--" ) break 2;; | |
"--staged") | |
STAGED=true | |
;; | |
*) | |
echo "Unknown option $optname while processing options" | |
exit 1 | |
;; | |
esac | |
done | |
# Get the tracking branch (if we're on a branch) | |
SVN_BRANCH=`git svn info | grep URL | sed -e 's/.*\/branches\///'` | |
if [[ "$SVN_BRANCH" =~ URL.* ]]; then | |
SVN_BRANCH=`git svn info | grep URL | sed -e 's/.*\/release-branches\///'` | |
fi | |
# If the tracking branch has 'URL' at the beginning, then the sed wasn't successful and | |
# we'll fall back to the svn-remote config option | |
if [[ "$SVN_BRANCH" =~ URL.* ]]; then | |
SVN_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'` | |
fi | |
REV=`git svn find-rev $(git rev-list --date-order --max-count=1 remotes/$SVN_BRANCH)` | |
TRACKING_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
lf=$'\n' | |
tab=$'\t' | |
GIT_REVISION_FILTER='' | |
if [ $STAGED ]; then | |
GIT_REVISION_FILTER='--staged' | |
else | |
GIT_REVISION_FILTER="$(git rev-list --date-order --max-count=1 $TRACKING_BRANCH)" | |
fi | |
git diff --no-prefix $GIT_REVISION_FILTER | | |
sed " | |
# New files have /dev/null as their original path | |
/^--- \/dev\/null/{ | |
# Read a line into the pattern space | |
N | |
# Do a multiline substitution | |
s/^--- \/dev\/null\n+++ \(.*\)$/--- \1\\${tab}(revision 0)\\${lf}+++ \1\\${tab} (working copy)/ | |
# Jump to the end of the script. This skips the next two substitutions | |
b end | |
} | |
s/^+++ .*/&\\${tab}(working copy)/ | |
s/^--- .*/&\\${tab}(revision $REV)/ | |
s/^diff --git [^[:space:]]*/Index:/ | |
s/^index.*/===================================================================/ | |
: end | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment