Created
June 22, 2016 12:15
-
-
Save superfawkes/c555b58f590d27a0e5b43b42a9fc34ad to your computer and use it in GitHub Desktop.
Git Diff to Svn Diff - compatible with Crucible andCode Review software
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 | |
# | |
# 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 | |
# modified by superfawkes - correct whitespaces in aconway's patch for Crucible, handle whitespaces for BSD/OSX styled sed | |
# | |
# 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. | |
# note: On OS X (or BSD), sed interprets RHS literally in s/// - workaround: capture \n, replace tab by [tab] | |
git diff --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $* | | |
sed -e "/--- \/dev\/null/{ N; s|^--- /dev/null\(\n\)+++ \(.*\)|--- \2 (revision 0)\1+++ \2 (working copy)|;}" \ | |
-e "s/^--- .*/& (revision $REV)/" \ | |
-e "s/^+++ .*/& (working copy)/" \ | |
-e "s/^diff --git [^[:space:]]*/Index:/" \ | |
-e "/^new file mode/d" \ | |
-e "s/^index.*/===================================================================/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for lines
27-32
!git diff
is bad to read, but svn diff is good.