Skip to content

Commit

Permalink
Check that parent_tag is in an ancestor of the checked out branch
Browse files Browse the repository at this point in the history
`git rev-list A..B` returns the set of commits present in B but not
A. Only if A is an ancestor of B will the cardinality of the set be
the same as the forward-running offset from A to B.
  • Loading branch information
jengelh committed Nov 8, 2017
1 parent dfd0b0b commit c25018e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions TarSCM/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ def _detect_version_tag_offset(self, parent_tag, versionformat):
sys.exit("\033[31m@TAG_OFFSET@ cannot be expanded, "
"as no parent tag was discovered.\033[0m")

rcode, tgcommit = self.helpers.run_cmd(
["git", "rev-parse", parent_tag + "^{}"],
self.clone_dir
)
if rcode:
sys.exit("\033[31m`git rev-parse " + parent_tag + "` failed: " +
output + "\033[0m")
rcode, head = self.helpers.run_cmd(
["git", "rev-parse", "HEAD"],
self.clone_dir
)
if rcode:
sys.exit("\033[31m`git rev-parse HEAD` failed: " +
output + "\033[0m")
rcode, mgbase = self.helpers.run_cmd(
["git", "merge-base", parent_tag, "HEAD"],
self.clone_dir
)
tgcommit = tgcommit.strip()
head = head.strip()
mgbase = mgbase.strip()
if mgbase != tgcommit:
sys.exit("\033[31mparent_tag is not an ancestor of HEAD. " +
"Cannot compute a (meaningful) distance.\033[0m")
rcode, output = self.helpers.run_cmd(
['git', 'rev-list', '--count', parent_tag + '..HEAD'],
self.clone_dir
Expand Down

0 comments on commit c25018e

Please sign in to comment.