Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that parent_tag is in an ancestor of the checked out branch #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions TarSCM/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

from TarSCM.scm.base import Scm

def color_red(s):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes no sense, there's just one line above every def

if not os.isatty(1):
return s
return "\033[0;31m" + s + "\033[0m"

class Git(Scm):
scm = 'git'
Expand Down Expand Up @@ -200,9 +204,8 @@ def _detect_parent_tag(self, args):

def _detect_version_parent_tag(self, parent_tag, versionformat): # noqa pylint: disable=no-self-use
if not parent_tag:
sys.exit("\033[31mNo parent tag present for the checked out "
"revision, thus @PARENT_TAG@ cannot be expanded."
"\033[0m")
sys.exit(color_red("No parent tag present for the checked out "
"revision, thus @PARENT_TAG@ cannot be expanded."))

versionformat = re.sub('@PARENT_TAG@', parent_tag,
versionformat)
Expand All @@ -213,14 +216,20 @@ 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(color_red("parent_tag is not an ancestor of HEAD. " +
"Cannot compute a (meaningful) distance."))

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

if rcode:
msg = "\033[31m@TAG_OFFSET@ can not be expanded: %s\033[0m"
msg.format(out)
sys.exit(msg)
sys.exit(color_red("@TAG_OFFSET@ can not be expanded: " + output))

tag_offset = out.strip()
versionformat = re.sub('@TAG_OFFSET@', tag_offset,
Expand Down