Skip to content

Instantly share code, notes, and snippets.

@jake-low
Last active August 29, 2015 14:19
Show Gist options
  • Save jake-low/ebce856a48cbc98f0141 to your computer and use it in GitHub Desktop.
Save jake-low/ebce856a48cbc98f0141 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# git-svn-diff
#
# Generate an SVN-compatible diff against the tip of the tracking branch. Useful if you
# use git svn (ie. your organization is on SVN but you prefer git) and you need to be
# able to generate SVN-compatible patches for code review tools like ReviewBoard, or
# other code-sharing purposes.
#
# Modified from Cristoph's script, as posted here: http://stackoverflow.com/a/4308184/1085300
TRACKING_BRANCH=`git config --get svn-remote.origin.fetch | sed -e 's/.*:refs\/remotes\///'`
REV=`git svn find-rev $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH)`
git diff --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $* |
sed \
-e "s/^+++ .*/& (working copy)/" \
-e "s/^--- .*/& (revision $REV)/" \
-e "s/^diff --git [^[:space:]]*/Index:/" \
-e "s/^index.*/===================================================================/" |
awk '\
{ f=0 }
/^--- \/dev\/null/ \
{ getline; split($0,a," "); print "--- " a[2] " (revision 0)"; print $0; f=1 } \
/^+++ \/dev\/null/ \
{ split(line,a," "); print "+++ " a[2] " (working copy)"; f=1 } \
f==0 { line = $0; print line }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment