Merge "Handle shallow checkout of SHA1 pinned repos"

This commit is contained in:
Conley Owens 2015-01-28 20:29:37 +00:00 committed by Gerrit Code Review
commit ee69084421

View File

@ -1764,8 +1764,15 @@ class Project(object):
if is_sha1 or tag_name is not None: if is_sha1 or tag_name is not None:
if self._CheckForSha1(): if self._CheckForSha1():
return True return True
if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)): if is_sha1 and not depth:
current_branch_only = False # When syncing a specific commit and --depth is not set:
# * if upstream is explicitly specified and is not a sha1, fetch only
# upstream as users expect only upstream to be fetch.
# Note: The commit might not be in upstream in which case the sync
# will fail.
# * otherwise, fetch all branches to make sure we end up with the
# specific commit.
current_branch_only = self.upstream and not ID_RE.match(self.upstream)
if not name: if not name:
name = self.remote.name name = self.remote.name
@ -1842,12 +1849,17 @@ class Project(object):
spec.append(tag_name) spec.append(tag_name)
branch = self.revisionExpr branch = self.revisionExpr
if is_sha1: if is_sha1 and depth:
branch = self.upstream # Shallow checkout of a specific commit, fetch from that commit and not
if branch is not None and branch.strip(): # the heads only as the commit might be deeper in the history.
if not branch.startswith('refs/'): spec.append(branch)
branch = R_HEADS + branch else:
spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) 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)))
cmd.extend(spec) cmd.extend(spec)
shallowfetch = self.config.GetString('repo.shallowfetch') shallowfetch = self.config.GetString('repo.shallowfetch')