Created
April 15, 2021 20:06
-
-
Save Chemaclass/435a8b14bd44471a14c3c5d3e2b8a0a1 to your computer and use it in GitHub Desktop.
Is descent git branch
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
pushedrev=$1 | |
basename=${2:-develop} | |
if ! baserev="$(git rev-parse --verify refs/heads/"$basename" 2>/dev/null)"; then | |
echo "'$basename' is missing, call for help!" | |
exit 1 | |
fi | |
parents_of_commits_beyond_base="$( | |
git rev-list --pretty=tformat:%P "$pushedrev" --not "$baserev" | | |
grep -v '^commit ' | |
)" | |
case "$parents_of_commits_beyond_base" in | |
*\ *) echo "$pushedrev must not push merge commits (rebase instead)" | |
exit 1 ;; | |
*"$baserev"*) exit 0 ;; | |
*) echo "$pushedrev must descend from tip of '$basename'" | |
exit 1 ;; | |
esac | |
# usage example: ~/scripts/is_descent_branch.sh child-name parent-branch | |
# Read more about it in https://stackoverflow.com/a/3162929/3454593 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment