Skip to content

Command git merge-base --is-ancestor not working as expected #321

Closed
@bwrsandman

Description

@bwrsandman

Description

Using:

  • git version 2.4.6
  • gitdb==0.6.4
  • GitPython==1.0.1

The use case for git merge-base --is-ancestor from git manpage:

Check if the first is an ancestor of the second , and exit with status 0 if true, or with status 1 if not. Errors are signaled by a non-zero status that is not 1.

Related to #169 (comment)

The problem is that the output of git merge-base --is-ancestor comes from the return code and unlike without the --is-ancestor flag, this command doesn't return commit SHAs but is a simple yes-no check. The current implementation doesn't take into account the return code and the command cannot be usefully run.

Current Behaviour

revA is ancestor to revB

$ git merge-base --is-ancestor $revA $revB; echo $?
0
>>> repo.merge_base(revA, revB, is_ancestor=True)
[ ]

revA is not ancestor to revB

$ git merge-base --is-ancestor $revA $revB; echo $?
1
>>> repo.merge_base(revA, revB, is_ancestor=True)
[ ]

revA is not ancestor to revB and revB doesn't exist

$ git merge-base --is-ancestor $revA $revB; echo $?
fatal: Not a valid commit name $revB
128
>>> repo.merge_base(revA, revB, is_ancestor=True)
GitCommandError: 'git merge-base --is-ancestor $revA $revB' returned with exit code 128
stderr: 'fatal: Not a valid commit name $revB'

Desired Behaviour

When the kwarg is_ancestor is used, don't return a list, but return a bool that is true if the return code is 0. Return False if return code is 1. Raise Error as before for all other cases

$ git merge-base --is-ancestor $revA $revB; echo $?
0
>>> repo.merge_base(revA, revB, is_ancestor=True)
True

revA is not ancestor to revB

$ git merge-base --is-ancestor $revA $revB; echo $?
1
>>> repo.merge_base(revA, revB, is_ancestor=True)
False

revA is not ancestor to revB and revB doesn't exist

$ git merge-base --is-ancestor $revA $revB; echo $?
fatal: Not a valid commit name $revB
128
>>> repo.merge_base(revA, revB, is_ancestor=True)
GitCommandError: 'git merge-base --is-ancestor $revA $revB' returned with exit code 128
stderr: 'fatal: Not a valid commit name $revB'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions