Allow to always drop pq branch after export
authorGuido Günther <agx@sigxcpu.org>
Fri, 12 Sep 2014 11:05:47 +0000 (13:05 +0200)
committerGuido Günther <agx@sigxcpu.org>
Fri, 12 Sep 2014 11:48:34 +0000 (13:48 +0200)
Closes: #761160

gbp/config.py
gbp/scripts/pq.py
tests/13_test_gbp_pq.py

index e0cd779..0580cc5 100644 (file)
@@ -155,6 +155,7 @@ class GbpOptionParser(OptionParser):
                  'allow-unauthenticated': 'False',
                  'symlink-orig': 'True',
                  'purge': 'True',
+                 'drop': 'False',
              }
     help = {
              'debian-branch':
@@ -294,6 +295,9 @@ class GbpOptionParser(OptionParser):
                    "'%(symlink-orig)s'"),
               'purge':
                   "Purge exported package build directory. Default is '%(purge)s'",
+              'drop':
+                  ("In case of 'export' drop the patch-queue branch "
+                   "after export. Default is '%(drop)s'"),
            }
 
     def_config_files = [ '/etc/git-buildpackage/gbp.conf',
index 3186de5..80520d4 100755 (executable)
@@ -94,6 +94,9 @@ def export_patches(repo, branch, options):
     else:
         gbp.log.info("No patches on '%s' - nothing to do." % pq_branch)
 
+    if options.drop:
+        drop_pq(repo, branch)
+
 
 def safe_patches(series):
     """
@@ -234,6 +237,7 @@ def build_parser(name):
                       help="verbose command execution")
     parser.add_option("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into")
     parser.add_config_file_option(option_name="time-machine", dest="time_machine", type="int")
+    parser.add_boolean_config_file_option("drop", dest='drop')
     parser.add_option("--force", dest="force", action="store_true", default=False,
                       help="in case of import even import if the branch already exists")
     parser.add_config_file_option(option_name="color", dest="color", type='tristate')
index 753143d..910ce20 100644 (file)
@@ -21,7 +21,7 @@ import os
 import logging
 import unittest
 
-from gbp.scripts.pq import generate_patches
+from gbp.scripts.pq import generate_patches, switch_pq, export_patches
 import gbp.scripts.common.pq as pq
 import gbp.patch_series
 import tests.testutils as testutils
@@ -132,5 +132,26 @@ class TestWritePatch(testutils.DebianGitTestRepo):
         # Branches must be identical afterwards
         self.assertEqual('', diff)
 
+class TestExport(testutils.DebianGitTestRepo):
+    class Options(object):
+        drop = True
+        patch_numbers = False
+
+    def setUp(self):
+        testutils.DebianGitTestRepo.setUp(self)
+        self.add_file('bar', 'bar')
+
+    def test_drop(self):
+        """Test if we drop the patch-queue branch with --drop"""
+        repo = self.repo
+        start = repo.get_branch()
+        pq = os.path.join('patch-queue', start)
+        switch_pq(repo, start)
+        self.assertEqual(repo.get_branch(), pq)
+        export_patches(repo, pq, TestExport.Options)
+        self.assertEqual(repo.get_branch(), start)
+        self.assertFalse(repo.has_branch(pq))
+
+
 def _patch_path(name):
     return os.path.join(context.projectdir, 'tests/data', name)