Last active
December 26, 2015 13:39
-
-
Save Idorobots/7160066 to your computer and use it in GitHub Desktop.
A handy replacement for plain `git merge`.
This file contains hidden or 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/sh | |
# This little script will automatically test feature-branch code | |
# before it is actually merged into the master branch. | |
# Just alias it as so: | |
# git config --global alias.safe-merge '!exec $HOME/git_safe_merge.sh' | |
LAST_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
TEMP_BRANCH=`date +"$LAST_BRANCH-%Y%m%d%H%M"` | |
# Store any working changes. | |
# git stash | |
# Create a new, temporary branch. | |
git checkout -b $TEMP_BRANCH | |
# Merge new changes... | |
if git merge --no-ff $@ | |
then | |
# ...run tests to make sure new code is ok. | |
if [ ! -f ./runtests.sh ] || ./runtests.sh | |
then | |
# If so, fast-forward the main branch. | |
git checkout $LAST_BRANCH | |
git rebase $TEMP_BRANCH | |
else | |
# Otherwise discard the changes. | |
git checkout -q -f $LAST_BRANCH | |
fi | |
else | |
# Otherwise discard the changes. | |
git checkout -q -f $LAST_BRANCH | |
fi | |
# Remove the temporary branch. | |
git branch -D $TEMP_BRANCH | |
# Restore working changes. | |
# git stash pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Success output:
Merge conflict:
Test failure: