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)
committerJun Wang <junbill.wang@samsung.com>
Fri, 29 Jan 2016 11:36:42 +0000 (19:36 +0800)
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 7e10c46..56db5e1 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')