Skip to content

Instantly share code, notes, and snippets.

@ern
Created May 12, 2015 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ern/c50c534734c2d9cb25fa to your computer and use it in GitHub Desktop.
Save ern/c50c534734c2d9cb25fa to your computer and use it in GitHub Desktop.
Shell script for merging from git to subversion
gitmerge() {
#Commands this needs
CURL=`which curl`
GREP="/usr/bin/grep"
AWK=`which awk`
TR=`which tr`
UNIQ=`which uniq`
SVN=`which svn`
MKTEMP=`which mktemp`
CUT=`which cut`
PASTE=`which paste`
PBCOPY=`which pbcopy`
tmpdir=$( $MKTEMP -d /tmp/XXX )
if [ "$1" ]; then
echo "Created temp directory $tmpdir"
tmpfile=$tmpdir/$1
command $CURL -sL https://github.com/sakaiproject/sakai/pull/$1.patch > $tmpfile
$SVN --strip 0 patch $tmpfile 2>&1 | tee $tmpdir/svn.results
if [ "$?" = "0" ]; then
tool=`$GREP "^+++" $tmpfile | $CUT -d '/' -f 2 | $UNIQ | $PASTE -s -d ' ' -`
if [ -n "${tool}" ]; then
echo "Patching succeeded to [$tool]"
conflicts=$( $GREP "^C" $tmpdir/svn.results )
if [ -n "${conflicts}" ]; then
echo "There were conflicts see $tmpdir/svn.results, please fix the rejects"
else
echo "Removing temp directory $tmpdir"
rm -rf $tmpdir
fi
else
echo "Tool was not identified in the patch"
return
fi
else
echo "There was some failure patching, please check the output above"
return
fi
if [ -n "$2" ]; then
PASTE_BUFFER="svn commit -m \"$2 merge PR $1 from git\" $tool"
else
PASTE_BUFFER="svn commit -m \"SAK-XXXXX merge PR $1 from git\" $tool"
fi
echo -n "$PASTE_BUFFER" | $PBCOPY
echo "Copied to clipboard: $PASTE_BUFFER"
else
echo "USAGE:"
echo " gitmerge PR# JIRA#"
echo " examples:"
echo " gitmerge 278"
echo " gitmerge 278 SAK-29150"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment