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>
Tue, 7 Jan 2014 14:21:29 +0000 (16:21 +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
tests/component/rpm/data

index 28a7c44e31d8a18132803688efb65e379bfb5213..607c3c9e3c3571a3e57fa05c74979c6e2e900044 100644 (file)
@@ -556,6 +556,7 @@ class GbpOptionParserRpm(GbpOptionParser):
                        'pristine-tarball-name'  : 'auto',
                        'orig-prefix'            : 'auto',
                        'patch-import'           : 'True',
+                       'spec-vcs-tag'           : '',
                      } )
 
     help = dict(GbpOptionParser.help)
@@ -590,6 +591,10 @@ class GbpOptionParserRpm(GbpOptionParser):
                         "Prefix (dir) to be used when generating/importing tarballs, default is '%(orig-prefix)s'",
                    'patch-import':
                         "Import patches to the packaging branch, default is '%(patch-import)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'"),
                  } )
 
 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
index b889fdeefb37062475f7807a0e81f21212413333..f63e9e5de68109133babdb85a416767268bbb5a3 100755 (executable)
@@ -410,6 +410,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)
@@ -584,12 +585,29 @@ def main(argv):
             repo.create_tag(name=tag, msg="%s release %s" % (options.vendor,
                             RpmPkgPolicy.compose_full_version(spec.version)),
                             sign=options.sign_tags, keyid=options.keyid, commit=tree)
+            tree_name = 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:
index 4aa7e2901ab84bd91c1d2289dd4138c531c19376..aec4222cbd9e2efbd60c56ee4e9cc4d8eb7265b3 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4aa7e2901ab84bd91c1d2289dd4138c531c19376
+Subproject commit aec4222cbd9e2efbd60c56ee4e9cc4d8eb7265b3