Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Last active April 5, 2022 08:01

Revisions

  1. simonwhitaker revised this gist Aug 27, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git-is-ancestor
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,9 @@
    # [alias]
    # is-ancestor = !/path/to/git-is-ancestor
    #
    # Then use thus:
    #
    # $ git is-ancestor rev1 rev2

    script_name=$(basename $0)

  2. simonwhitaker renamed this gist Aug 27, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. simonwhitaker created this gist Aug 27, 2013.
    37 changes: 37 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/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
    #

    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