diff options
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/git/repository.py | 49 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage_rpm.py | 4 |
2 files changed, 36 insertions, 17 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 77c7cf7a..31a4eb49 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -624,37 +624,56 @@ class GitRepository(object): out, ret = self._git_getoutput('tag', [ '-l', tag ]) return [ False, True ][len(out)] - def find_tag(self, commit, pattern=None, longfmt=False, always=False): + def describe(self, commitish, pattern=None, longfmt=False, always=False, + abbrev=None): """ - Find the closest tag to a given commit + Describe commit, relative to the latest tag reachable from it. - @param commit: the commit to describe - @type commit: C{str} + @param commitish: the commit-ish to describe + @type commitish: C{str} @param pattern: only look for tags matching I{pattern} @type pattern: C{str} - @param longfmt: return the tag in the long format + @param longfmt: describe the commit in the long format @type longfmt: C{bool} - @param always: return commit sha1 as fallback + @param always: return commit sha1 as fallback if no tag is found @type always: C{bool} - @return: the found tag + @param abbrev: abbreviate sha1 to given length instead of the default + @type abbrev: None or C{long} + @return: tag name plus/or the abbreviated sha1 @rtype: C{str} """ args = GitArgs() args.add_true(pattern, ['--match' , pattern]) - if not longfmt and not always: - args.add('--abbrev=0') - else: - args.add_true(longfmt, '--long') - args.add_true(always, '--always') - args.add(commit) + args.add_true(longfmt, '--long') + # 'long' and 'abbrev=0' are incompatible, behave similar to + # 'always' and 'abbrev=0' + if longfmt and abbrev == 0: + args.add('--abbrev=40') + elif abbrev is not None: + args.add('--abbrev=%s' % abbrev) + args.add_true(always, '--always') + args.add(commitish) tag, err, ret = self._git_inout('describe', args.args, capture_stderr=True) if ret: - raise GitRepositoryError("Can't find tag for %s. Git error: %s" % \ - (commit, err.strip())) + raise GitRepositoryError("Can't describe %s. Git error: %s" % \ + (commitish, err.strip())) return tag.strip() + def find_tag(self, commit, pattern=None): + """ + Find the closest tag to a given commit + + @param commit: the commit to describe + @type commit: C{str} + @param pattern: only look for tags matching I{pattern} + @type pattern: C{str} + @return: the found tag + @rtype: C{str} + """ + return self.describe(commit, pattern, abbrev=0) + def get_tags(self, pattern=None): """ List tags diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 33c5f447..831d85f2 100755 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -603,10 +603,10 @@ def main(argv): 'GBP_SHA1': sha})() else: try: - tree_name = repo.find_tag(tree, longfmt=True, always=True) + tree_name = repo.describe(tree, longfmt=True, always=True) except GitRepositoryError: # If tree is not commit-ish, expect it to be from current HEAD - tree_name = repo.find_tag('HEAD', longfmt=True, always=True) +\ + tree_name = repo.describe('HEAD', longfmt=True, always=True) +\ '-dirty' # Put 'VCS:' tag to .spec spec.set_tag('VCS', None, |