diff --git a/TarSCM/scm/git.py b/TarSCM/scm/git.py index db0338f1..12e22ad4 100644 --- a/TarSCM/scm/git.py +++ b/TarSCM/scm/git.py @@ -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