Bug#669145: [PATCH] Add git-dch --commit and --commit-msg options
authorMatthijs Kooijman <matthijs@stdin.nl>
Tue, 17 Apr 2012 20:17:20 +0000 (22:17 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 18 Apr 2012 22:23:28 +0000 (00:23 +0200)
Closes: #669145
Signed-off-by: Guido Günther <agx@sigxcpu.org>
docs/manpages/git-dch.sgml
gbp/config.py
gbp/scripts/dch.py

index 6dfe7bb9852b925a74b7d076f741b24c80df1cb9..bf67d500131721d42db4ca9e0f87f87feb4bcef5 100644 (file)
@@ -37,6 +37,8 @@
       <arg><option>--[no-]git-author</option></arg>
       <arg><option>--[no-]multimaint-merge</option></arg>
       <arg><option>--spawn-editor=[always|snapshot|release]</option></arg>
+      <arg><option>--commit-msg=</option><replaceable>msg-format</replaceable></arg>
+      <arg><option>--commit</option></arg>
       <arg choice="plain"><replaceable>[path1 path2]</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
          when doing a release.</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--commit-msg=</option><replaceable>msg-format</replaceable>
+        </term>
+        <listitem>
+         <para>use this format string for the commit message when
+         committing the generated changelog file (when
+         <option>--commit</option> is given). Default is
+         <replaceable>Update changelog for %(version)s
+         release</replaceable></para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>--commit</option>
+        </term>
+        <listitem>
+         <para>Commit the generated changelog.</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
index 35c78b4034f2b9696a7a7740feb4fe2b989bdb27..d406d1ecf161e75da8ac8c656228e3bbc2a41b6b 100644 (file)
@@ -86,6 +86,7 @@ class GbpOptionParser(OptionParser):
                  'debian-tag'      : 'debian/%(version)s',
                  'upstream-tag'    : 'upstream/%(version)s',
                  'import-msg'      : 'Imported Upstream version %(version)s',
+                 'commit-msg'      : 'Update changelog for %(version)s release',
                  'filter'          : [],
                  'snapshot-number' : 'snapshot + 1',
                  'git-log'         : '--no-merges',
@@ -144,7 +145,9 @@ class GbpOptionParser(OptionParser):
              'keyid':
                   "GPG keyid to sign tags with, default is '%(keyid)s'",
              'import-msg':
-                  "format string for commit message, default is '%(import-msg)s'",
+                  "format string for git-import-orig commit message, default is '%(import-msg)s'",
+             'commit-msg':
+                  "format string for git-dch commit message, default is '%(commit-msg)s'",
              'pristine-tar':
                   "use pristine-tar to create orig tarball, default is '%(pristine-tar)s'",
              'pristine-tar-commit':
index 3a4a02ad5def8eb1d4fe48ee5984166c3f5e5e61..14dff29573f1fac53055875d200c25c056bb8f4b 100644 (file)
@@ -246,7 +246,6 @@ def do_snapshot(changelog, repo, next_snapshot):
     mangle_changelog(changelog, cp, commit)
     return snapshot, commit
 
-
 def parse_commit(repo, commitid, opts, last_commit=False):
     """Parse a commit and return message, author, and author email"""
     commit_info = repo.get_commit_info(commitid)
@@ -324,6 +323,10 @@ def process_editor_option(options):
         return None
 
 
+def changelog_commit_msg(options, version):
+    return options.commit_msg % dict(version=version)
+
+
 def main(argv):
     ret = 0
     changelog = 'debian/changelog'
@@ -392,6 +395,10 @@ def main(argv):
     commit_group.add_boolean_config_file_option(option_name="multimaint", dest="multimaint")
     commit_group.add_boolean_config_file_option(option_name="multimaint-merge", dest="multimaint_merge")
     commit_group.add_config_file_option(option_name="spawn-editor", dest="spawn_editor")
+    parser.add_config_file_option(option_name="commit-msg",
+                      dest="commit_msg")
+    parser.add_option("-c", "--commit", action="store_true", dest="commit", default=False,
+                      help="commit changelog file after generating")
 
     help_msg = ('Load Python code from CUSTOMIZATION_FILE.  At the moment,'
                 ' the only useful thing the code can do is define a custom'
@@ -516,6 +523,16 @@ def main(argv):
         if editor_cmd:
             gbpc.Command(editor_cmd, ["debian/changelog"])()
 
+        if options.commit:
+            # Get the version from the changelog file (since dch might
+            # have incremented it, there's no way we can already know
+            # the version).
+            version = ChangeLog(filename=changelog).version
+            # Commit the changes to the changelog file
+            msg = changelog_commit_msg(options, version)
+            repo.commit_files([changelog], msg)
+            gbp.log.info("Changelog has been committed for version %s" % version)
+
     except (GbpError, GitRepositoryError, NoChangeLogError), err:
         if len(err.__str__()):
             gbp.log.err(err)