add postimport hook for git-import-orig
authorGuido Günther <agx@sigxcpu.org>
Sun, 23 Aug 2009 14:46:15 +0000 (16:46 +0200)
committerGuido Günther <agx@sigxcpu.org>
Sun, 23 Aug 2009 16:40:14 +0000 (18:40 +0200)
Allows to run git-dch after import. Drop the dch invocation and warn
when --no-dch gets passed on the commandline.

Closes: #520355

docs/manpages/git-import-orig.sgml
gbp.conf
gbp/config.py
git-import-orig

index 7c19adf..84811b4 100644 (file)
@@ -24,7 +24,6 @@
       <arg><option>--verbose</option></arg>
       <arg><option>--upstream-version=</option><replaceable>version</replaceable></arg>
       <arg><option>--no-merge</option></arg>
-      <arg><option>--no-dch</option></arg>
       <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
       <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
       <arg><option>--[no-]sign-tags</option></arg>
@@ -33,6 +32,7 @@
       <arg><option>--filter=</option><replaceable>pattern</replaceable></arg>
       <arg><option>--[no-]pristine-tar</option></arg>
       <arg><option>--[no-]filter-pristine-tar</option></arg>
+      <arg><option>--postimport=cmd</option></arg>
       <arg choice="plain"><replaceable>upstream-source</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
          <para>Don't merge the upstream version to the development branch</para>
         </listitem>
       </varlistentry>
-      <varlistentry>
-        <term><option>--no-dch</option></term>
-        <listitem>
-         <para>don't call dch after the import</para>
-        </listitem>
-      </varlistentry>
+
       <varlistentry>
         <term><option>--upstream-branch</option>=<replaceable>branch_name</replaceable>
         </term>
          passed to pristine tar</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--postimport=<replaceable>cmd</replaceable></option></term>
+        <listitem>
+         <para>run <replaceable>cmd</replaceable> after the import.</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
index ce6fc11..0401132 100644 (file)
--- a/gbp.conf
+++ b/gbp.conf
 #filter = .svn
 # filter out files from tarball passed to pristine tar
 #filter-pristine-tar = True
+# hook run after the import:
+#postimport = git-dch -N%(version)s -S -a
+# emulate old behaviour of calling dch:
+#postimport = dch -v%(version)s New Upstream Version
 
 # Options only affecting git-import-dsc
 [git-import-dsc]
index 9aec395..f670ad5 100644 (file)
@@ -36,6 +36,7 @@ class GbpOptionParser(OptionParser):
                  'keyid'           : '',
                  'posttag'         : '',
                  'postbuild'       : '',
+                 'postimport'      : '',
                  'debian-tag'      : 'debian/%(version)s',
                  'upstream-tag'    : 'upstream/%(version)s',
                  'filter'          : [],
@@ -50,7 +51,6 @@ class GbpOptionParser(OptionParser):
                  'meta-closes'     : 'Closes|LP',
                  'full'            : 'False',
                  'id-length'       : '0',
-                 'no-dch'          : 'False',
                  'git-author'      : 'False',
              }
     help = {
index fff8838..63d12f9 100755 (executable)
@@ -221,13 +221,11 @@ def main(argv):
                       "options related to git tag creation")
     branch_group = GbpOptionGroup(parser, "version and branch naming options",
                       "version number and branch layout options")
+    cmd_group = GbpOptionGroup(parser, "external command options", "how and when to invoke external commands and hooks")
 
-    for group in [import_group, branch_group, cl_group, tag_group ]:
+    for group in [import_group, branch_group, cl_group, tag_group, cmd_group ]:
         parser.add_option_group(group)
 
-    cl_group.add_config_file_option(option_name="no-dch", dest='no_dch',
-                      help="don't call dch after the import", action="store_true")
-
     branch_group.add_option("-u", "--upstream-version", dest="version",
                       help="Upstream Version")
     branch_group.add_config_file_option(option_name="debian-branch",
@@ -254,14 +252,24 @@ def main(argv):
                       dest="pristine_tar")
     import_group.add_boolean_config_file_option(option_name="filter-pristine-tar",
                       dest="filter_pristine_tar")
+    cmd_group.add_config_file_option(option_name="postimport", dest="postimport",
+                      help="hook run after a successful import, default is '%(postimport)s'")
 
     parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
                       help="verbose command execution")
+
+    # Accepted for compatibility
+    parser.add_option("--no-dch", dest='no_dch', action="store_true",
+                      default=False, help="deprecated - don't use.")
+
     (options, args) = parser.parse_args(argv[1:])
 
     if options.verbose:
         gbpc.Command.verbose = True
 
+    if options.no_dch:
+        print >>sys.stderr, "'--no-dch' passed. This is now the default, please remove this option."
+
     if options.filters:
         turn_off_fastimport(options, "Import filters currently not supported with fastimport.")
 
@@ -369,14 +377,15 @@ on howto create it otherwise use --upstream-branch to specify it.
                 try:
                     gbpc.GitMerge(tag)()
                 except gbpc.CommandExecFailed:
-                    raise GbpError, """Merge failed, please resolve and run "dch -v %s-1".""" % version
-                if not options.no_dch:
+                    raise GbpError, """Merge failed, please resolve.""" % version
+                if options.postimport:
                     epoch = ''
                     if os.access('debian/changelog', os.R_OK):
                         cp = parse_changelog('debian/changelog')
                         if has_epoch(cp):
                             epoch = '%s:' % cp['Epoch']
-                    gbpc.Dch("%s%s-1" % (epoch, version), 'New Upstream Version')()
+                    info = { 'version': "%s%s-1" % (epoch, version) }
+                    cmd = gbpc.Command(options.postimport % info, shell=True)()
         except gbpc.CommandExecFailed:
             raise GbpError, "Import of %s failed" % archive
     except GbpNothingImported, err: