Skip to content

Commit

Permalink
Merge pull request #524 from jkloetzke/fix-520
Browse files Browse the repository at this point in the history
Handle nested git tags
  • Loading branch information
jkloetzke authored Jul 5, 2023
2 parents d9deb77 + 2c84a73 commit 2be1d30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pym/bob/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,15 @@ def status(self, workspacePath):
status.add(ScmTaint.switched,
"> commit: configured: '{}', actual: '{}'".format(self.__commit, output))
elif self.__tag:
output = self.callGit(workspacePath, 'tag', '--points-at', 'HEAD').splitlines()
if self.__tag not in output:
currentCommit = self.callGit(workspacePath, 'rev-parse', 'HEAD')
tagCommit = self.callGit(workspacePath, 'rev-parse',
'refs/tags/'+self.__tag+'^{commit}',
check=False)
if (not currentCommit) or (currentCommit != tagCommit):
output = self.callGit(workspacePath, 'tag', '--points-at', 'HEAD').splitlines()
actual = ("'" + ", ".join(output) + "'") if output else "not on any tag"
status.add(ScmTaint.switched,
"> tag: configured: '{}', actual: {}".format(self.__tag, actual))

# Need to check if the tag still exists. Otherwise the "git
# log" command at the end will trip.
try:
self.callGit(workspacePath, 'rev-parse', 'tags/'+self.__tag)
except BuildError:
pass
elif self.__branch:
output = self.callGit(workspacePath, 'rev-parse', '--abbrev-ref', 'HEAD')
if output != self.__branch:
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_input_gitscm_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ def testOrphanedOk(self):
s = self.statusGitScm({ 'tag' : 'v1.1' })
self.assertEqual(s.flags, set())

def testNestedTagOk(self):
self.callGit('git fetch origin tag v1.1', cwd=self.repodir_local)
self.callGit('git tag -a -m nested nested v1.1', cwd=self.repodir_local)
self.callGit('git tag -a -m double double nested', cwd=self.repodir_local)
self.callGit('git checkout tags/double', cwd=self.repodir_local)
s = self.statusGitScm({ 'tag' : 'double' })
self.assertEqual(s.flags, set())


class TestSubmodulesStatus(TestCase):

Expand Down

0 comments on commit 2be1d30

Please sign in to comment.