buildpackage-rpm: look for remote upstream branches
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 19 Nov 2014 15:19:20 +0000 (17:19 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 21 Nov 2014 08:33:36 +0000 (10:33 +0200)
Consider remote branches, too, while looking for the upstream branch
when trying to guess if a package is native or not.

Change-Id: I3dbbb49816d1d294d81209ea5ab5870e053fd66a
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/buildpackage_rpm.py
tests/component/rpm/test_buildpackage_rpm.py

index dcfa3ac..4b24723 100755 (executable)
@@ -288,7 +288,17 @@ def export_patches(repo, spec, export_treeish, options):
 def is_native(repo, options):
     """Determine whether a package is native or non-native"""
     if options.native.is_auto():
-        return not repo.has_branch(options.upstream_branch)
+        if repo.has_branch(options.upstream_branch):
+            return False
+        # Check remotes, too
+        for remote_branch in repo.get_remote_branches():
+            remote, branch = remote_branch.split('/', 1)
+            if branch == options.upstream_branch:
+                gbp.log.debug("Found upstream branch '%s' from remote '%s'" %
+                               (remote, branch))
+                return False
+        return True
+
     return options.native.is_on()
 
 
index 3060f84..88a66fc 100644 (file)
@@ -139,10 +139,16 @@ class TestGbpRpm(RpmRepoTestBase):
 
     def test_non_native_build(self):
         """Basic test of non-native pkg"""
-        self.init_test_repo('gbp-test')
+        repo = self.init_test_repo('gbp-test')
         eq_(mock_gbp([]), 0)
         self.check_rpms('../rpmbuild/RPMS/*')
 
+        # Test nativity guessing from remote branches by creating a dummy
+        # remote branch
+        repo.update_ref('refs/remotes/fooremote/foobranch',
+                        'srcdata/gbp-test/upstream')
+        eq_(mock_gbp(['--git-upstream-branch=foobranch']), 0)
+
     def test_option_native(self):
         """Test the --git-native option"""
         self.init_test_repo('gbp-test2')