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.

When parent-tag is implicit, the tag `git-describe` chooses is
already known to be an ancestor. Only when this is explicitly
overridden with a different parent-tag in the _service file, it will
be possible for the chosen parent-tag value not to refer to a commit
that is a valid ancestor.
  • Loading branch information
jengelh committed Nov 12, 2018
1 parent 56833cb commit 7cb40ee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TarSCM/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ 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, output = self.helpers.run_cmd(
["git", "merge-base", "--is-ancestor", parent_tag, "HEAD"],
self.clone_dir
)
if rcode != 0:
sys.exit("\033[31mparent_tag is not an ancestor of HEAD. " +
"Cannot compute a (meaningful) distance.\033[0m")

cmd = self._get_scm_cmd()
cmd.extend(['rev-list', '--count', parent_tag + '..HEAD'])
rcode, out = self.helpers.run_cmd(cmd, self.clone_dir)
Expand Down

0 comments on commit 7cb40ee

Please sign in to comment.