Fix repo mirror with --current-branch

Before a2cd6aeae8, "repo mirror with --current-branch" fetches git data
using command
    git fetch --progress --update-head-ok cros --tags
No refspec is specified, thus it fetches default refspec, which is +refs/heads/*:refs/heads/*

After a2cd6aeae8, the fetch command became
     git fetch --progress --update-head-ok cros --tags +refs/tags/*:refs/tags/*
It did not only add tags refspec, but also suppressed the fetching of default refspec.

In other words, repo mirrors doesn't work if current_branch_only=True.
This CL explicitly adds the default refspec to command line if none is
specified.

Bug: https://crbug.com/gerrit/11990
Change-Id: Iadcf7b9aa50f53c47132cfe6c53b3fb2076ebca2
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/246632
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Kuang-che Wu <kcwu@chromium.org>
This commit is contained in:
Kuang-che Wu 2019-11-25 12:37:55 +08:00 committed by Mike Frysinger
parent 34bc5712eb
commit 6856f98467

View File

@ -2235,16 +2235,6 @@ class Project(object):
cmd.append('--update-head-ok') cmd.append('--update-head-ok')
cmd.append(name) cmd.append(name)
spec = []
# If using depth then we should not get all the tags since they may
# be outside of the depth.
if no_tags or depth:
cmd.append('--no-tags')
else:
cmd.append('--tags')
spec.append(str((u'+refs/tags/*:') + remote.ToLocal('refs/tags/*')))
if force_sync: if force_sync:
cmd.append('--force') cmd.append('--force')
@ -2254,6 +2244,7 @@ class Project(object):
if submodules: if submodules:
cmd.append('--recurse-submodules=on-demand') cmd.append('--recurse-submodules=on-demand')
spec = []
if not current_branch_only: if not current_branch_only:
# Fetch whole repo # Fetch whole repo
spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')))
@ -2261,19 +2252,33 @@ class Project(object):
spec.append('tag') spec.append('tag')
spec.append(tag_name) spec.append(tag_name)
if not self.manifest.IsMirror: branch = self.revisionExpr
branch = self.revisionExpr if (not self.manifest.IsMirror and is_sha1 and depth
if is_sha1 and depth and git_require((1, 8, 3)): and git_require((1, 8, 3))):
# Shallow checkout of a specific commit, fetch from that commit and not # Shallow checkout of a specific commit, fetch from that commit and not
# the heads only as the commit might be deeper in the history. # the heads only as the commit might be deeper in the history.
spec.append(branch) spec.append(branch)
else: else:
if is_sha1: if is_sha1:
branch = self.upstream branch = self.upstream
if branch is not None and branch.strip(): if branch is not None and branch.strip():
if not branch.startswith('refs/'): if not branch.startswith('refs/'):
branch = R_HEADS + branch branch = R_HEADS + branch
spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
# If mirroring repo and we cannot deduce the tag or branch to fetch, fetch
# whole repo.
if self.manifest.IsMirror and not spec:
spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')))
# If using depth then we should not get all the tags since they may
# be outside of the depth.
if no_tags or depth:
cmd.append('--no-tags')
else:
cmd.append('--tags')
spec.append(str((u'+refs/tags/*:') + remote.ToLocal('refs/tags/*')))
cmd.extend(spec) cmd.extend(spec)
ok = False ok = False