Last active
April 5, 2022 08:01
-
-
Save simonwhitaker/6354592 to your computer and use it in GitHub Desktop.
A script to determine whether one git commit is the ancestor of another
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 | |
# | |
# git-is-ancestor, by Simon Whitaker | |
# | |
# Suggested usage | |
# | |
# Store this file somewhere, make it executable, then alias | |
# it to git is-ancestor by putting this in your $HOME/.gitconfig: | |
# | |
# [alias] | |
# is-ancestor = !/path/to/git-is-ancestor | |
# | |
# Then use thus: | |
# | |
# $ git is-ancestor rev1 rev2 | |
script_name=$(basename $0) | |
usage() | |
{ | |
cat << EOF >&2 | |
usage: ${script_name} <REV1> <REV2> | |
EOF | |
} | |
if [ $# -ne 2 ]; then | |
usage | |
exit 2 | |
fi | |
if $( git merge-base --is-ancestor $1 $2 ); then | |
echo "$1 is an ancestor of $2" | |
exit 0 | |
elif $( git merge-base --is-ancestor $2 $1 ); then | |
echo "$2 is an ancestor of $1" | |
exit 0 | |
else | |
echo "$1 and $2 are not related" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You definitely don't want run the stdout of the command (if any, fortunately none for now.)
Looks completely POSIX to me, so why not
/bin/sh
?