Last active
August 29, 2015 14:26
-
-
Save ScreamingDev/cc5669a81ebcd7964a43 to your computer and use it in GitHub Desktop.
Look up when two branches get in trouble
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
#!/usr/bin/env bash | |
# | |
# Usage: git when-conflict master | |
# | |
# - Be on a clean branch (double check via `git status`). | |
# - Test that branch against another one (e.g. "master"). | |
# | |
# Cheers! | |
# | |
currentHash=$(git rev-parse --abbrev-ref HEAD) | |
baseHash=$(git merge-base $1 $currentHash) | |
echo "From $baseHash to $currentHash:" | |
function testMerge() { | |
git merge --abort &> /dev/null | |
for testHash in $(git log --reverse --pretty=format:"%H" $baseHash..$1); do | |
echo -n $testHash ... | |
git merge --no-commit --no-ff $testHash &> /dev/null | |
mergeStatus=$? | |
if [[ $mergeStatus -ne 0 ]]; then | |
echo "FAILED!" | |
git log -n1 --pretty=format:" %h %ci %cn (%ce) %s" | |
echo "" | |
echo " Files with conflict:" | |
git diff --name-only --diff-filter=U | sed 's/^/ /' | |
git merge --abort &> /dev/null | |
return | |
fi | |
echo " clean!" | |
done | |
} | |
echo "Merging $currentHash into $1 ..." | |
testMerge $1 | |
git checkout origin/$1 &> /dev/null | |
echo "Merging $1 into $currentHash ..." | |
testMerge $currentHash | |
git checkout $currentHash &> /dev/null | |
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "$currentHash" ]]; then | |
echo "Could not return to normal live." | |
echo "Please checkout "$currentHash" before continuing!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment