summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'project.py')
-rw-r--r--project.py51
1 files changed, 34 insertions, 17 deletions
diff --git a/project.py b/project.py
index 45860d228..7186e58ad 100644
--- a/project.py
+++ b/project.py
@@ -2857,6 +2857,18 @@ class Project:
2857 2857
2858 return True 2858 return True
2859 2859
2860 def _GetUpstreamFallback(self) -> Optional[str]:
2861 """Resolve a fallback upstream ref when revisionExpr is a SHA-1."""
2862 for cand in (
2863 self.dest_branch,
2864 self.manifest.default.upstreamExpr,
2865 self.manifest.default.destBranchExpr,
2866 self.manifest.default.revisionExpr,
2867 ):
2868 if cand and not IsId(cand):
2869 return cand
2870 return None
2871
2860 def _RemoteFetch( 2872 def _RemoteFetch(
2861 self, 2873 self,
2862 name=None, 2874 name=None,
@@ -2890,14 +2902,31 @@ class Project:
2890 current_branch_only = True 2902 current_branch_only = True
2891 2903
2892 is_sha1 = IsId(self.revisionExpr) 2904 is_sha1 = IsId(self.revisionExpr)
2905 upstream = self.upstream
2893 2906
2894 if current_branch_only: 2907 if current_branch_only:
2908 if is_sha1 and not depth:
2909 # When syncing a specific commit and --depth is not set:
2910 # * if upstream is explicitly specified and is not a sha1, fetch
2911 # only upstream as users expect only upstream to be fetch.
2912 # Note: The commit might not be in upstream in which case the
2913 # sync will fail.
2914 # * otherwise, fetch all branches to make sure we end up with
2915 # the specific commit.
2916 if not upstream:
2917 upstream = self._GetUpstreamFallback()
2918
2919 if upstream:
2920 current_branch_only = not IsId(upstream)
2921 else:
2922 current_branch_only = False
2923
2895 if self.revisionExpr.startswith(R_TAGS): 2924 if self.revisionExpr.startswith(R_TAGS):
2896 # This is a tag and its commit id should never change. 2925 # This is a tag and its commit id should never change.
2897 tag_name = self.revisionExpr[len(R_TAGS) :] 2926 tag_name = self.revisionExpr[len(R_TAGS) :]
2898 elif self.upstream and self.upstream.startswith(R_TAGS): 2927 elif upstream and upstream.startswith(R_TAGS):
2899 # This is a tag and its commit id should never change. 2928 # This is a tag and its commit id should never change.
2900 tag_name = self.upstream[len(R_TAGS) :] 2929 tag_name = upstream[len(R_TAGS) :]
2901 2930
2902 if is_sha1 or tag_name is not None: 2931 if is_sha1 or tag_name is not None:
2903 has_shallow = os.path.exists( 2932 has_shallow = os.path.exists(
@@ -2915,18 +2944,6 @@ class Project:
2915 "persistent ref)" % self.name 2944 "persistent ref)" % self.name
2916 ) 2945 )
2917 return True 2946 return True
2918 if is_sha1 and not depth:
2919 # When syncing a specific commit and --depth is not set:
2920 # * if upstream is explicitly specified and is not a sha1, fetch
2921 # only upstream as users expect only upstream to be fetch.
2922 # Note: The commit might not be in upstream in which case the
2923 # sync will fail.
2924 # * otherwise, fetch all branches to make sure we end up with
2925 # the specific commit.
2926 if self.upstream:
2927 current_branch_only = not IsId(self.upstream)
2928 else:
2929 current_branch_only = False
2930 2947
2931 if not name: 2948 if not name:
2932 name = self.remote.name 2949 name = self.remote.name
@@ -3038,11 +3055,11 @@ class Project:
3038 # Shallow checkout of a specific commit, fetch from that commit and 3055 # Shallow checkout of a specific commit, fetch from that commit and
3039 # not the heads only as the commit might be deeper in the history. 3056 # not the heads only as the commit might be deeper in the history.
3040 spec.append(branch) 3057 spec.append(branch)
3041 if self.upstream: 3058 if upstream:
3042 spec.append(self.upstream) 3059 spec.append(upstream)
3043 else: 3060 else:
3044 if is_sha1: 3061 if is_sha1:
3045 branch = self.upstream 3062 branch = upstream
3046 if branch is not None and branch.strip(): 3063 if branch is not None and branch.strip():
3047 if not branch.startswith("refs/"): 3064 if not branch.startswith("refs/"):
3048 branch = R_HEADS + branch 3065 branch = R_HEADS + branch