summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2014-11-25 16:19:29 -0800
committerBertrand SIMONNET <bsimonnet@google.com>2015-01-21 14:14:23 -0800
commit3000cdad2237abe1f956f8109e385891e1a96d17 (patch)
tree370e613827df97302ac94c833385f674f56e8a2e
parent3eb87cec5cae5f43becfe9fd1ff94de855cac08c (diff)
downloadgit-repo-3000cdad2237abe1f956f8109e385891e1a96d17.tar.gz
Handle shallow checkout of SHA1 pinned repos
When doing a shallow checkout SHA1 pinned repos with repo init --depth=1 and repo sync -c, repo would try to fetch only some reference and fail if the exact SHA1 repo was missing. Instead, when depth is set, fetch only the specific commit. Change-Id: If3f799d0e78c03faea47f796380bb5e367b11998
-rw-r--r--project.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/project.py b/project.py
index cdce1e84..b9a53dce 100644
--- a/project.py
+++ b/project.py
@@ -1763,8 +1763,15 @@ class Project(object):
1763 if is_sha1 or tag_name is not None: 1763 if is_sha1 or tag_name is not None:
1764 if self._CheckForSha1(): 1764 if self._CheckForSha1():
1765 return True 1765 return True
1766 if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)): 1766 if is_sha1 and not depth:
1767 current_branch_only = False 1767 # When syncing a specific commit and --depth is not set:
1768 # * if upstream is explicitly specified and is not a sha1, fetch only
1769 # upstream as users expect only upstream to be fetch.
1770 # Note: The commit might not be in upstream in which case the sync
1771 # will fail.
1772 # * otherwise, fetch all branches to make sure we end up with the
1773 # specific commit.
1774 current_branch_only = self.upstream and not ID_RE.match(self.upstream)
1768 1775
1769 if not name: 1776 if not name:
1770 name = self.remote.name 1777 name = self.remote.name
@@ -1841,12 +1848,17 @@ class Project(object):
1841 spec.append(tag_name) 1848 spec.append(tag_name)
1842 1849
1843 branch = self.revisionExpr 1850 branch = self.revisionExpr
1844 if is_sha1: 1851 if is_sha1 and depth:
1845 branch = self.upstream 1852 # Shallow checkout of a specific commit, fetch from that commit and not
1846 if branch is not None and branch.strip(): 1853 # the heads only as the commit might be deeper in the history.
1847 if not branch.startswith('refs/'): 1854 spec.append(branch)
1848 branch = R_HEADS + branch 1855 else:
1849 spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch))) 1856 if is_sha1:
1857 branch = self.upstream
1858 if branch is not None and branch.strip():
1859 if not branch.startswith('refs/'):
1860 branch = R_HEADS + branch
1861 spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
1850 cmd.extend(spec) 1862 cmd.extend(spec)
1851 1863
1852 shallowfetch = self.config.GetString('repo.shallowfetch') 1864 shallowfetch = self.config.GetString('repo.shallowfetch')