Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Windows and TortoiseSVN-friendly modifications
# git-svn-diff originally by (
# modified by
# modified by aconway@[redacted] - handle diffs that introduce new files
# Generate an SVN-compatible diff against the tip of the tracking branch
# Get the tracking branch (if we're on a branch)
TRACKING_BRANCH=`git svn info | grep URL | sed -e 's/.*\/branches\///'`
# 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 [[ "$TRACKING_BRANCH" =~ URL.* ]]
TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'`
# Get the highest revision number
REV=`git svn info | grep 'Last Changed Rev:' | sed -E 's/^.*: ([[:digit:]]*)/\1/'`
# Then do the diff from the highest revision on the current branch
# and masssage into SVN format
git diff --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $* |
sed -e "s/^--- .*/& (revision $REV)/" \
-e "s/^+++ .*/& (working copy)/" \
-e "s/^diff --git [^[:space:]]*/Index:/" \
-e "s/^index.*/===================================================================/" \
-e "/^--- \/dev\/null (revision $REV)$/{N;s/--- \/dev\/null (revision $REV)\n+++ \(.*\) (working copy)/--- \1 (revision 0)\n+++ \1 (working copy)/}" \
-e "/^--- .* (revision $REV)$/{N;s/--- \(.*\) (revision $REV)\n+++ \/dev\/null (working copy)/--- \1 (revision $REV)\n+++ \1 (working copy)/}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment