diff options
author | Kuang-che Wu <kcwu@chromium.org> | 2019-11-25 12:37:55 +0800 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-11-25 20:12:34 +0000 |
commit | 6856f98467aa5c98085cdee02587dbab984cebb1 (patch) | |
tree | 1107564123796e6e099eae47c4912cee6b40986a /project.py | |
parent | 34bc5712eb7e09f9fc5b39ae78786775ad3023e8 (diff) | |
download | git-repo-6856f98467aa5c98085cdee02587dbab984cebb1.tar.gz |
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>
Diffstat (limited to 'project.py')
-rwxr-xr-x | project.py | 51 |
1 files changed, 28 insertions, 23 deletions
@@ -2235,16 +2235,6 @@ class Project(object): | |||
2235 | cmd.append('--update-head-ok') | 2235 | cmd.append('--update-head-ok') |
2236 | cmd.append(name) | 2236 | cmd.append(name) |
2237 | 2237 | ||
2238 | spec = [] | ||
2239 | |||
2240 | # If using depth then we should not get all the tags since they may | ||
2241 | # be outside of the depth. | ||
2242 | if no_tags or depth: | ||
2243 | cmd.append('--no-tags') | ||
2244 | else: | ||
2245 | cmd.append('--tags') | ||
2246 | spec.append(str((u'+refs/tags/*:') + remote.ToLocal('refs/tags/*'))) | ||
2247 | |||
2248 | if force_sync: | 2238 | if force_sync: |
2249 | cmd.append('--force') | 2239 | cmd.append('--force') |
2250 | 2240 | ||
@@ -2254,6 +2244,7 @@ class Project(object): | |||
2254 | if submodules: | 2244 | if submodules: |
2255 | cmd.append('--recurse-submodules=on-demand') | 2245 | cmd.append('--recurse-submodules=on-demand') |
2256 | 2246 | ||
2247 | spec = [] | ||
2257 | if not current_branch_only: | 2248 | if not current_branch_only: |
2258 | # Fetch whole repo | 2249 | # Fetch whole repo |
2259 | spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) | 2250 | spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) |
@@ -2261,19 +2252,33 @@ class Project(object): | |||
2261 | spec.append('tag') | 2252 | spec.append('tag') |
2262 | spec.append(tag_name) | 2253 | spec.append(tag_name) |
2263 | 2254 | ||
2264 | if not self.manifest.IsMirror: | 2255 | branch = self.revisionExpr |
2265 | branch = self.revisionExpr | 2256 | if (not self.manifest.IsMirror and is_sha1 and depth |
2266 | if is_sha1 and depth and git_require((1, 8, 3)): | 2257 | and git_require((1, 8, 3))): |
2267 | # Shallow checkout of a specific commit, fetch from that commit and not | 2258 | # Shallow checkout of a specific commit, fetch from that commit and not |
2268 | # the heads only as the commit might be deeper in the history. | 2259 | # the heads only as the commit might be deeper in the history. |
2269 | spec.append(branch) | 2260 | spec.append(branch) |
2270 | else: | 2261 | else: |
2271 | if is_sha1: | 2262 | if is_sha1: |
2272 | branch = self.upstream | 2263 | branch = self.upstream |
2273 | if branch is not None and branch.strip(): | 2264 | if branch is not None and branch.strip(): |
2274 | if not branch.startswith('refs/'): | 2265 | if not branch.startswith('refs/'): |
2275 | branch = R_HEADS + branch | 2266 | branch = R_HEADS + branch |
2276 | spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) | 2267 | spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) |
2268 | |||
2269 | # If mirroring repo and we cannot deduce the tag or branch to fetch, fetch | ||
2270 | # whole repo. | ||
2271 | if self.manifest.IsMirror and not spec: | ||
2272 | spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) | ||
2273 | |||
2274 | # If using depth then we should not get all the tags since they may | ||
2275 | # be outside of the depth. | ||
2276 | if no_tags or depth: | ||
2277 | cmd.append('--no-tags') | ||
2278 | else: | ||
2279 | cmd.append('--tags') | ||
2280 | spec.append(str((u'+refs/tags/*:') + remote.ToLocal('refs/tags/*'))) | ||
2281 | |||
2277 | cmd.extend(spec) | 2282 | cmd.extend(spec) |
2278 | 2283 | ||
2279 | ok = False | 2284 | ok = False |