-
-
Save anshulguleria/7f107ce67a0fe23c1b0b to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# 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/.*\/dev\///'` | |
# echo $TRACKING_BRANCH | |
# 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 | |
# echo $TRACKING_BRANCH | |
# 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.*/===================================================================/" | |
SVN_INFO=`git svn info` | |
REPO_ROOT=`echo "$SVN_INFO" | grep "Repository Root:" | \ | |
sed -e 's/Repository Root: //' \ | |
-e 's:/:\\\/:g'` | |
# Needed to escape forward slashes also | |
# Get the highest revision number | |
if ! [[ "$REV" ]] | |
then | |
REV=`echo "$SVN_INFO" | grep 'Last Changed Rev:' | sed -E 's/^.*: ([[:digit:]]*)/\1/'` | |
fi | |
if ! [[ "$TRACKING_BRANCH" ]] | |
then | |
TRACKING_BRANCH=`echo "$SVN_INFO" | grep "URL" | sed -e "s/.*$REPO_ROOT\///"` | |
BRANCH_DIR=`git config --get svn-remote.svn.branches | sed -e 's/\*\:refs.*//' \ | |
-e 's:/:\\\/:g'` | |
# Change / to \/ | |
TAG_DIR=`git config --get svn-remote.svn.tags | sed -e 's/\*\:refs.*//' \ | |
-e 's:/:\\\/:g'` | |
# Change / to \/ | |
# Remove branch/tag name from TRACKING_BRANCH which ever | |
# is present | |
if [[ `echo "$TRACKING_BRANCH" | grep "^$BRANCH_DIR"` ]] | |
then | |
TRACKING_BRANCH=`echo "$TRACKING_BRANCH" | sed -e "s/^$BRANCH_DIR//"` | |
elif [[ `echo "$TRACKING_BRANCH" | grep "^$TAG_DIR"` ]] | |
then | |
TRACKING_BRANCH=`echo "$TRACKING_BRANCH" | sed -e "s/^$TAG_DIR//"` | |
fi | |
fi | |
# since we expect diff to provided as pipe thus | |
DIFF=$(cat) | |
# Convert git diff to svn patch | |
echo "$DIFF" | | |
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.*/===================================================================/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment