Created
August 18, 2016 13:54
-
-
Save Osse/f104ea3b8bb015b72b24aca1db6928fa to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Assuming master is the main branch and first argument is topic branch | |
topicsha=$(git rev-parse "$1") | |
mergebase=$(git merge-base master "$1") | |
if [[ $topicsha != $mergebase ]]; then | |
# Not merged yet! ez | |
git diff master..."$1" | |
else | |
# Oh no, it's already merged. Find merge in log | |
# This prints sha parent1sha [ parent2sha ... ] | |
mergecommit=$(git log --format='%H %P' | | |
awk -vtopicsha="$topicsha" ' $3 == topicsha { print $1; exit }' | |
) | |
if [[ -n $mergecommit ]]; then | |
# ez | |
git diff "$mergecommit^1...$mergecommit^2" | |
else | |
echo oops >&2; | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment