diff --git a/scm.py b/scm.py index 36bb69d15..4e8123056 100644 --- a/scm.py +++ b/scm.py @@ -253,6 +253,10 @@ class GIT(object): ref = GIT.Capture(['symbolic-ref', ref], cwd=cwd) if not ref.endswith('master'): return ref + except subprocess2.CalledProcessError: + pass + + try: # Check if there are changes in the default branch for this # particular repository. GIT.Capture(['remote', 'set-head', '-a', remote], cwd=cwd) diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index f4ed08567..5cee7364d 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -411,6 +411,9 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): options = self.Options() options.merge = True scm = gclient_scm.GitWrapper(self.url, self.root_dir, self.relpath) + # This sets correct remote HEAD + scm.update(options, (), []) + scm._Run(['checkout', '-q', 'feature'], options) rev = scm.revinfo(options, (), None) file_list = [] @@ -432,12 +435,15 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): return options = self.Options() scm = gclient_scm.GitWrapper(self.url, self.root_dir, self.relpath) + # This sets correct remote HEAD + scm.update(options, (), []) + scm._Run(['checkout', '-q', 'feature'], options) - file_list = [] # Fake a 'y' key press. scm._AskForData = self._GetAskForDataCallback( 'Cannot fast-forward merge, attempt to rebase? ' '(y)es / (q)uit / (s)kip : ', 'y') + file_list = [] scm.update(options, (), file_list) self.assertEqual(file_list, [join(self.base_path, x) for x in ['a', 'b', 'c']]) diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index b9f93a580..e298c5cdf 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -101,6 +101,7 @@ class GitWrapperTestCase(unittest.TestCase): @mock.patch('os.path.exists', lambda _: True) def testGetRemoteHeadRefRemote(self, mockCapture): mockCapture.side_effect = [ + subprocess2.CalledProcessError(1, '', '', '', ''), subprocess2.CalledProcessError(1, '', '', '', ''), 'ref: refs/heads/main\tHEAD\n' + '0000000000000000000000000000000000000000\tHEAD', @@ -108,7 +109,7 @@ class GitWrapperTestCase(unittest.TestCase): self.assertEqual( 'refs/remotes/origin/main', scm.GIT.GetRemoteHeadRef('foo', 'proto://url', 'origin')) - self.assertEqual(mockCapture.call_count, 2) + self.assertEqual(mockCapture.call_count, 3) @mock.patch('scm.GIT.Capture') def testIsVersioned(self, mockCapture):