Commit e1482c55 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Refresh remote HEAD if matches legacy default

If remote HEAD returns legacy default branch, refresh HEAD by running
set-head to check if there are any changes.

R=gavinmak@google.com

Change-Id: I5891a899b512e81fccfb086a056d497c906df4b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3152593
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
parent 28c91628
......@@ -201,6 +201,12 @@ class GIT(object):
try:
# Try using local git copy first
ref = 'refs/remotes/%s/HEAD' % remote
ref = GIT.Capture(['symbolic-ref', ref], cwd=cwd)
if not ref.endswith('master'):
return ref
# Check if there are changes in the default branch for this particular
# repository.
GIT.Capture(['remote', 'set-head', '-a', remote], cwd=cwd)
return GIT.Capture(['symbolic-ref', ref], cwd=cwd)
except subprocess2.CalledProcessError:
pass
......
......@@ -107,6 +107,18 @@ class GitWrapperTestCase(unittest.TestCase):
scm.GIT.GetRemoteHeadRef('foo', 'proto://url', 'origin'))
self.assertEqual(mockCapture.call_count, 1)
@mock.patch('scm.GIT.Capture')
@mock.patch('os.path.exists', lambda _: True)
def testGetRemoteHeadRefLocalUpdateHead(self, mockCapture):
mockCapture.side_effect = [
'refs/remotes/origin/master', # first symbolic-ref call
'foo', # set-head call
'refs/remotes/origin/main', # second symbolic-ref call
]
self.assertEqual('refs/remotes/origin/main',
scm.GIT.GetRemoteHeadRef('foo', 'proto://url', 'origin'))
self.assertEqual(mockCapture.call_count, 3)
@mock.patch('scm.GIT.Capture')
@mock.patch('os.path.exists', lambda _:True)
def testGetRemoteHeadRefRemote(self, mockCapture):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment