Created
May 12, 2015 21:51
-
-
Save ern/c50c534734c2d9cb25fa to your computer and use it in GitHub Desktop.
Shell script for merging from git to subversion
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
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