import_dsc: Create missing debian branch with --create-missing-branches
authorGuido Günther <agx@sigxcpu.org>
Sun, 23 Feb 2014 15:59:44 +0000 (16:59 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 23 Feb 2014 16:55:44 +0000 (17:55 +0100)
Closes: #739888

gbp/scripts/import_dsc.py
tests/component/deb/data
tests/component/deb/test_import_dsc.py

index d60e0d1..630422b 100644 (file)
@@ -377,7 +377,8 @@ def main(argv):
                         repo.create_branch(options.upstream_branch, commit)
                     if options.pristine_tar:
                         repo.pristine_tar.commit(src.tgz, options.upstream_branch)
-                if is_empty and not repo.has_branch(options.debian_branch):
+                if (not repo.has_branch(options.debian_branch)
+                    and (is_empty or options.create_missing_branches)):
                     repo.create_branch(options.debian_branch, commit)
             if not src.native:
                 if src.diff or src.deb_tgz:
index fce347e..a06e148 160000 (submodule)
@@ -1 +1 @@
-Subproject commit fce347ecd0739fe29776a761775a92456a362af9
+Subproject commit a06e148c09b6f9c9057ecdcabcbeed7d71ba0a18
index bccdb07..da16615 100644 (file)
@@ -1,6 +1,6 @@
 # vim: set fileencoding=utf-8 :
 #
-# (C) 2013 Guido Günther <agx@sigxcpu.org>
+# (C) 2013,2014 Guido Günther <agx@sigxcpu.org>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -22,10 +22,12 @@ from tests.component import (ComponentTestBase,
                              ComponentTestGitRepository)
 from tests.component.deb import DEB_TEST_DATA_DIR
 
+from nose.tools import ok_
+
 from gbp.scripts.import_dsc import main as import_dsc
 
 class TestImportDsc(ComponentTestBase):
-    """Test importing of src.rpm files"""
+    """Test importing of debian source packages"""
 
     def test_debian_import(self):
         """Test that importing of debian native packages works"""
@@ -50,3 +52,31 @@ class TestImportDsc(ComponentTestBase):
         assert import_dsc(['arg0', dsc]) == 0
         self._check_repo_state(repo, 'master', ['master'])
         assert len(repo.get_commits()) == 3
+
+    def test_create_branches(self):
+        """Test if creating missing branches works"""
+        def _dsc(version):
+            return os.path.join(DEB_TEST_DATA_DIR,
+                                'dsc-3.0',
+                                'hello-debhelper_%s.dsc' % version)
+
+        dsc = _dsc('2.6-2')
+        assert import_dsc(['arg0',
+                           '--pristine-tar',
+                           '--debian-branch=master',
+                           '--upstream-branch=upstream',
+                           dsc]) == 0
+        repo = ComponentTestGitRepository('hello-debhelper')
+        os.chdir('hello-debhelper')
+        assert len(repo.get_commits()) == 2
+        self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
+        dsc = _dsc('2.8-1')
+        assert import_dsc(['arg0',
+                           '--pristine-tar',
+                           '--debian-branch=foo',
+                           '--upstream-branch=bar',
+                           '--create-missing-branches',
+                           dsc]) == 0
+        self._check_repo_state(repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream'])
+        commits, expected = len(repo.get_commits()), 2
+        ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))