Skip to content

Instantly share code, notes, and snippets.

@mojodna
Created January 8, 2009 02:06
Show Gist options
  • Save mojodna/44537 to your computer and use it in GitHub Desktop.
Save mojodna/44537 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by [email protected]
# 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.* ]]
then
TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'`
fi
# 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 "/--- \/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.*/===================================================================/"
@DanCraft99
Copy link

Line 26/27/28/29 has a sed syntax issue that prevents it from running on my OS X setup. Can you remove the empty space after each .

After removing the empty spaces, the script work nicely. Thank you.

@anshulguleria
Copy link

Removed the trailing spaces here https://gist.github.com/anshulguleria/7f107ce67a0fe23c1b0b
Was causing issue in linux also. Please add this change to your gist too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment