public
Last active — forked from mojodna/git-svn-diff.sh

git-svn-diff.sh

  • Download Gist
git-svn-diff.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by mike@mikepearce.net
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by t.broyer@ltgt.net - fixes 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.* ]]
then
TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'`
fi
 
# Get the highest revision number
REV=`git svn find-rev $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH)`
 
# 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 "/--- \/dev\/null/{ N; s|^--- /dev/null\n+++ \(.*\)|---\1 (revision 0)\n+++\1 (revision 0)|}" \
-e "s/^--- .*/& (revision $REV)/" \
-e "s/^+++ .*/& (working copy)/" \
-e "s/^diff --git [^[:space:]]*/Index:/" \
-e "s/^index.*/===================================================================/"

Line 26 has a sed syntax issue that prevents it from running on my OS X setup. I get this error:

sed: 1: "/--- \/dev\/null/{ N; s ...": bad flag in substitute command: '}'

You need a semicolon before the ending curly brace. Fixed here in my fork.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.