Skip to content

Instantly share code, notes, and snippets.

@DasBlub
Last active December 15, 2015 10:49
Show Gist options
  • Save DasBlub/5248614 to your computer and use it in GitHub Desktop.
Save DasBlub/5248614 to your computer and use it in GitHub Desktop.
little merge helper script. might need a finishing touch
#!/bin/sh
# Function to fetch and merge a pull reqest
# Call with param1 == remote, param2 == Number
function merge_pull_request {
echo "Now fetching and merging pull-request $2 (from remote $1)"
git fetch $1 +refs/pull/$2/head:refs/remotes/$1/pr/$2
[[ $? -eq 0 ]] || exit 1
git merge $1/pr/$2
[[ $? -eq 0 ]] || exit 1
}
[[ -d .git ]] || exit 1
if echo $1 | egrep -s "^([[:alnum:]_-]+)#([[:digit:]]+)$" ; then
remote=`echo $1 | sed -r 's@([[:alnum:]_-]+)#([[:digit:]]+)@\1@'`
PR=`echo $1 | sed -r 's@([[:alnum:]_-]+)#([[:digit:]]+)@\3@'`
merge_pull_request $remote $PR
elif echo $1 | egrep -s "^([[:alnum:]_-]+)/([[:alnum:]_-]+)$" ; then
remote=`echo $1 | sed -r 's@([[:alnum:]_-]+)/([[:alnum:]_-]+)@\1@'`
branch=`echo $1 | sed -r 's@([[:alnum:]_-]+)/([[:alnum:]_-]+)@\2@'`
git fetch $remote
git merge $remote/$branch
elif echo $1 | egrep -s "^([[:alnum:]_-]+)$" ; then
git merge $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment