buildpackage-rpm: support setting/updating the 'VCS:' tag
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 17 Jan 2013 08:41:18 +0000 (10:41 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:46:23 +0000 (14:46 +0200)
Git-buildpackage-rpm now always updates the 'VCS:' tag in the exported
spec file. A new config option 'spec-vcs-tag' controls the format:
- if empty, no 'VCS' tag is inserted and possible old 'VCS' tag is
  removed
- otherwise, a 'VCS' tag is inserted or the old 'VCS' tag is updated
- '%(tag)s' expands to the long tag name (from git-describe)

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/config.py
gbp/scripts/buildpackage_rpm.py

index 5509396..fdfc66c 100644 (file)
@@ -613,6 +613,7 @@ class GbpOptionParserRpm(GbpOptionParser):
             'patch-export-compress'     : '0',
             'patch-export-ignore-path'  : '',
             'patch-export-squash-until' : '',
+            'spec-vcs-tag'              : '',
             'merge'                     : 'False',
             'pristine-tarball-name'     : 'auto',
             'orig-prefix'               : 'auto',
@@ -659,6 +660,9 @@ class GbpOptionParserRpm(GbpOptionParser):
                 "Squash commits (from upstream) until given tree-ish into one "
                 "big diff, format is '<commit_ish>[:<filename_base>]'. "
                 "Default is '%(patch-export-squash-until)s'",
+            'spec-vcs-tag':
+                "Set/update the 'VCS:' tag in the spec file, empty value "
+                "removes the tag entirely, default is '%(spec-vcs-tag)s'",
             'pristine-tarball-name':
                 "Filename to record to pristine-tar, set to 'auto' to not "
                 "mangle the file name, default is '%(pristine-tarball-name)s'",
index f1b31f7..187e6b2 100755 (executable)
@@ -418,6 +418,7 @@ def parse_args(argv, prefix):
     export_group.add_config_file_option("patch-export-compress", dest="patch_export_compress")
     export_group.add_config_file_option("patch-export-squash-until", dest="patch_export_squash_until")
     export_group.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers")
+    export_group.add_config_file_option("spec-vcs-tag", dest="spec_vcs_tag")
     options, args = parser.parse_args(args)
 
     options.patch_export_compress = rpm.string_to_int(options.patch_export_compress)
@@ -590,12 +591,30 @@ def main(argv):
                 repo.delete_tag(tag)
             create_packaging_tag(repo, tag, commit=tree, version=spec.version,
                                  options=options)
+            tree_name = tag
+            commit_sha1 = repo.rev_parse('%s^0' % tag)
             if options.posttag:
                 sha = repo.rev_parse("%s^{}" % tag)
                 Command(options.posttag, shell=True,
                         extra_env={'GBP_TAG': tag,
                                    'GBP_BRANCH': branch,
                                    'GBP_SHA1': sha})()
+        else:
+            try:
+                tree_name = repo.describe(tree, longfmt=True, always=True,
+                                          abbrev=40)
+                commit_sha1 = repo.rev_parse('%s^0' % tree)
+            except GitRepositoryError:
+                # If tree is not commit-ish, expect it to be from current HEAD
+                tree_name = repo.describe('HEAD', longfmt=True, always=True,
+                                          abbrev=40) + '-dirty'
+                commit_sha1 = repo.rev_parse('HEAD') + '-dirty'
+        # Put 'VCS:' tag to .spec
+        spec.set_tag('vcs',
+                     options.spec_vcs_tag % {'tagname': tree_name,
+                                             'commit': commit_sha1})
+        spec.write_spec_file()
+
     except CommandExecFailed:
         retval = 1
     except GitRepositoryError as err: