From 6856f98467aa5c98085cdee02587dbab984cebb1 Mon Sep 17 00:00:00 2001 From: Kuang-che Wu Date: Mon, 25 Nov 2019 12:37:55 +0800 Subject: [PATCH] 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 Reviewed-by: Mike Frysinger Tested-by: Kuang-che Wu --- project.py | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/project.py b/project.py index 7811d6ba..6224bb45 100755 --- a/project.py +++ b/project.py @@ -2235,16 +2235,6 @@ class Project(object): cmd.append('--update-head-ok') 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: cmd.append('--force') @@ -2254,6 +2244,7 @@ class Project(object): if submodules: cmd.append('--recurse-submodules=on-demand') + spec = [] if not current_branch_only: # Fetch whole repo spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) @@ -2261,19 +2252,33 @@ class Project(object): spec.append('tag') spec.append(tag_name) - if not self.manifest.IsMirror: - branch = self.revisionExpr - if is_sha1 and depth and git_require((1, 8, 3)): - # Shallow checkout of a specific commit, fetch from that commit and not - # the heads only as the commit might be deeper in the history. - spec.append(branch) - else: - if is_sha1: - branch = self.upstream - if branch is not None and branch.strip(): - if not branch.startswith('refs/'): - branch = R_HEADS + branch - spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) + branch = self.revisionExpr + if (not self.manifest.IsMirror and is_sha1 and depth + and git_require((1, 8, 3))): + # Shallow checkout of a specific commit, fetch from that commit and not + # the heads only as the commit might be deeper in the history. + spec.append(branch) + else: + if is_sha1: + branch = self.upstream + if branch is not None and branch.strip(): + if not branch.startswith('refs/'): + branch = R_HEADS + 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) ok = False