import-orig: Allow to run a post unpack hook
authorGuido Günther <agx@sigxcpu.org>
Thu, 25 Apr 2019 15:15:21 +0000 (17:15 +0200)
committerGuido Günther <agx@sigxcpu.org>
Thu, 25 Apr 2019 15:34:00 +0000 (17:34 +0200)
The working directory of the hook is the top temporary directory the
tarballs are being unpacked into.

gbp/config.py
gbp/scripts/import_orig.py
tests/component/deb/test_import_orig.py

index 504118024b3a9643d971bc351e858d0d1741a128..d9a3cfaa5c7871dc6b6e8a488e72645e319d27dc 100644 (file)
@@ -160,6 +160,7 @@ class GbpOptionParser(OptionParser):
                 'postedit': '',
                 'postexport': '',
                 'postimport': '',
+                'postunpack': '',
                 'posttag': '',
                 'pq-from': 'DEBIAN',
                 'prebuild': '',
@@ -321,6 +322,9 @@ class GbpOptionParser(OptionParser):
         'postimport':
             "hook run after a successful import, "
             "default is '%(postimport)s'",
+        'postunpack':
+            "hook run after a unpacking the tarballs, "
+            "default is '%(postimport)s'",
         'hooks':
             "Enable running all hooks, default is %(hooks)s",
         'time-machine':
index 9c859f24db7470c997c52492ef384c5db2805fc8..01b1fc6d3bdc2eb7645de7f0c1b830c7e5d89fc4 100644 (file)
@@ -210,6 +210,14 @@ def postimport_hook(repo, tag, version, options):
              extra_env=env)()
 
 
+def postunpack_hook(repo, tmp_dir, options):
+    if options.postunpack:
+        Hook('Postunpack', options.postunpack,
+             extra_env={'GBP_GIT_DIR': repo.git_dir,
+                        'GBP_TMP_DIR': tmp_dir}
+             )(dir=tmp_dir)
+
+
 def is_30_quilt(repo, options):
     format_file = DebianSourceFormat.format_file
     try:
@@ -353,6 +361,7 @@ def build_parser(name):
     import_group.add_config_file_option("component", action="append", metavar='COMPONENT',
                                         dest="components")
     cmd_group.add_config_file_option(option_name="postimport", dest="postimport")
+    cmd_group.add_config_file_option(option_name="postunpack", dest="postunpack")
 
     parser.add_boolean_config_file_option(option_name="interactive",
                                           dest='interactive')
@@ -442,6 +451,10 @@ def main(argv):
             set_bare_repo_options(options)
 
         upstream, tmpdir = unpack_tarballs(name, upstream, version, component_tarballs, options)
+        try:
+            postunpack_hook(repo, tmpdir, options)
+        except gbpc.CommandExecFailed:
+            raise GbpError()  # The hook already printed an error message
 
         (pristine_orig, linked) = prepare_pristine_tar(upstream.path,
                                                        name,
index 58b72c5b1d82046a4693e31145d38db392087637..d7136822b3c50b2b1678cf33d2749421701b6f7b 100644 (file)
@@ -100,6 +100,7 @@ class TestImportOrig(ComponentTestBase):
         orig = self._orig('2.8')
         ok_(import_orig(['arg0',
                          '--postimport=printenv > ../postimport.out',
+                         '--postunpack=printenv > ../postunpack.out',
                          '--no-interactive', '--pristine-tar', orig]) == 0)
         self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
                                tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8'])