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: Gavin Mak <gavinmak@google.com>
changes/93/3152593/2
Josip Sokcevic 4 years ago committed by LUCI CQ
parent 28c9162830
commit e1482c5548

@ -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):

Loading…
Cancel
Save