Skip to content

Instantly share code, notes, and snippets.

@cestella
Created May 15, 2012 03:07
Show Gist options
  • Save cestella/2698798 to your computer and use it in GitHub Desktop.
Save cestella/2698798 to your computer and use it in GitHub Desktop.
use git-svn to generate patch files for a whole branch excluding the files changed only as part of a merge from a parent branch
#!/bin/bash
BRANCH_NAME=$1
shift
for project in $@;do
pushd $project >& /dev/null
MAX="";
MIN="";
CURR_FILE="";
#grab all files (full SVN path) and revisions from the branch that were not part of a commit
for FULL_FILE in $(for i in $(git log --grep="branches/$BRANCH_NAME" --no-merges --format=oneline | awk '{print $1}');do SVN_LINE=$(git show --name-only $i | grep "git-svn" | awk '{print $2}'); REVISION=$(echo $SVN_LINE | awk -F@ '{print $2}');SVN_URL=$(echo $SVN_LINE | awk -F@ '{print $1}'); for FILE in $(git show --name-only $i | grep "^[a-z]" | grep -v "commit" );do echo "$SVN_URL/$FILE@$REVISION";done ;done | sort -n);do
NEW_FILE=$(echo $FULL_FILE | awk -F@ '{print $1}');
NEW_REV=$(echo $FULL_FILE | awk -F@ '{print $2}');
#if we've hit a new file, then update FULL_PATH and generate a diff with the MIN and MAX revisions
if [[ "$CURR_FILE" != "$NEW_FILE" ]];then
FULL_PATH=$(dirname $CURR_FILE | sed 's;svn://mayfield/source/;;g');
svn diff $CURR_FILE@HEAD -r $MIN:$MAX | sed "s;Index: ;Index: $FULL_PATH/;g" | sed "s;--- ;--- $FULL_PATH/;g" | sed "s;+++ ;+++ $FULL_PATH/;g" ;
#don't forget to subtract one from the revision
#this ensures that a new file will be seen as an addition
MIN=$(($NEW_REV - 1));
MAX="$MIN";
CURR_FILE="$NEW_FILE";
else
MAX="$NEW_REV";
fi;
done
popd >& /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment