rpm-ch: implement --commit-msg option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 14:25:25 +0000 (17:25 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:47:20 +0000 (14:47 +0200)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
docs/manpages/gbp-rpm-ch.sgml
gbp/scripts/rpm_ch.py
tests/component/rpm/test_rpm_ch.py

index 37a4272..59adaa5 100644 (file)
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term><option>--commit-msg=</option><replaceable>MSG-FORMAT</replaceable>
+        </term>
+        <listitem>
+          <para>
+          Format string for the commit message when committing changes
+          (when <option>--commit</option> is given).
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>--tag</option>
         </term>
         <listitem>
index b509bd3..3caaac2 100755 (executable)
@@ -356,11 +356,22 @@ def update_changelog(changelog, entries, repo, spec, options):
         top_section.append_entry(entry)
     return (tag, commit_info['author'], commit_info['committer'])
 
-def commit_changelog(repo, changelog, author, committer, edit):
+def create_commit_message(spec, options):
+    """Generate commit message"""
+    fields = spec.version
+    fields['version'] = version=RpmPkgPolicy.compose_full_version(spec.version)
+    fields['vendor'] = options.vendor
+    try:
+        return options.commit_msg % fields
+    except KeyError as err:
+        raise GbpError("Unknown key %s in commit-msg string, "
+                       "only %s are accepted" % (err, fields.keys()))
+
+def commit_changelog(repo, changelog, message, author, committer, edit):
     """Commit changelog and create a packaging/release tag"""
     repo.add_files(changelog.path)
-    repo.commit_staged("Update changelog", author_info=author,
-                        committer_info=committer, edit=edit)
+    repo.commit_staged(message, author_info=author, committer_info=committer,
+                       edit=edit)
 
 
 def parse_args(argv):
@@ -446,6 +457,8 @@ def parse_args(argv):
     # Commit/tag group options
     commit_grp.add_option("-c", "--commit", action="store_true",
                     help="commit changes")
+    commit_grp.add_config_file_option(option_name="commit-msg",
+                                      dest="commit_msg")
     commit_grp.add_option("--tag", action="store_true",
                     help="commit the changes and create a packaging/release"
                          "tag")
@@ -498,7 +511,8 @@ def main(argv):
 
         if options.commit:
             edit = True if editor_cmd else False
-            commit_changelog(repo, ch_file, author, committer, edit)
+            msg = create_commit_message(spec, options)
+            commit_changelog(repo, ch_file, msg, author, committer, edit)
             if options.tag:
                 if options.retag and repo.has_tag(tag):
                     repo.delete_tag(tag)
index b8c3bca..b69c517 100644 (file)
@@ -287,6 +287,17 @@ class TestRpmCh(RpmRepoTestBase):
         eq_(repo.get_commit_info('HEAD')['files'],
             {'M': ['foo.txt', 'gbp-test.spec']})
 
+    def test_option_commit_msg(self):
+        """Test the --commit-msg cmdline option"""
+        repo = self.init_test_repo('gbp-test2')
+
+        eq_(mock_ch(['--commit', '--since=HEAD^', '--commit-msg=Foo']), 0)
+        eq_(repo.get_commit_info('HEAD')['subject'], 'Foo')
+
+        # Unknown key in format string causes failure
+        eq_(mock_ch(['--commit', '--since=HEAD^', '--commit-msg=%(foo)s']), 1)
+        self._check_log(-1, "gbp:error: Unknown key 'foo' in commit-msg string")
+
     def test_tagging(self):
         """Test commiting/tagging"""
         repo = self.init_test_repo('gbp-test-native')