Skip to content

Instantly share code, notes, and snippets.

@evhan
Created September 2, 2018 22:35
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 evhan/9380fbb81c2bb0a30e4f653468e68fa6 to your computer and use it in GitHub Desktop.
Save evhan/9380fbb81c2bb0a30e4f653468e68fa6 to your computer and use it in GitHub Desktop.
git-test-merge
#!/bin/sh -e
if ! git rev-parse --quiet --verify >/dev/null "${1}"
then
echo 1>&2 Not something we can merge: "${1}"
exit 1
fi
if test -n "$(git status --porcelain --untracked-files=no)"
then
echo 1>&2 Working directory must be clean.
exit 1
fi
trap '{
if git rev-parse --quiet --verify >/dev/null MERGE_HEAD
then
echo Rewinding merge.
git merge --abort
fi
}' EXIT
if git merge --quiet --no-commit --no-ff 2>/dev/null "${@}"
then
echo Merge will be successful.
else
echo Merge will cause conflicts.
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment