summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-02-28 22:03:04 -0500
committerMike Frysinger <vapier@google.com>2021-03-01 15:57:17 +0000
commit31fabeed54f3cbf9495e559dce60f58e126f58d5 (patch)
tree92788d850b7243dc7d25227499377ea53b36505c
parent76844ba2926b53ed56f2275365a6518d11310b95 (diff)
downloadgit-repo-31fabeed54f3cbf9495e559dce60f58e126f58d5.tar.gz
download: handle shared projects a bit better
If a manifest checksout a project multiple times, repo download isn't able to accurately pick the right project. We were just picking the first result which could be a bit random for the user. If we hit that situation, check if the cwd is one of the projects, and if it isn't, we emit an error and tell the user it's an ambiguous request. Bug: https://crbug.com/gerrit/13070 Change-Id: Id1059b81330229126b48c7312569b37504808383 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/298702 Reviewed-by: Michael Mortensen <mmortensen@google.com> Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r--subcmds/download.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/subcmds/download.py b/subcmds/download.py
index c0c47dd9..81d997e0 100644
--- a/subcmds/download.py
+++ b/subcmds/download.py
@@ -16,7 +16,7 @@ import re
16import sys 16import sys
17 17
18from command import Command 18from command import Command
19from error import GitError 19from error import GitError, NoSuchProjectError
20 20
21CHANGE_RE = re.compile(r'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$') 21CHANGE_RE = re.compile(r'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$')
22 22
@@ -60,6 +60,7 @@ If no project is specified try to use current directory as a project.
60 if m: 60 if m:
61 if not project: 61 if not project:
62 project = self.GetProjects(".")[0] 62 project = self.GetProjects(".")[0]
63 print('Defaulting to cwd project', project.name)
63 chg_id = int(m.group(1)) 64 chg_id = int(m.group(1))
64 if m.group(2): 65 if m.group(2):
65 ps_id = int(m.group(2)) 66 ps_id = int(m.group(2))
@@ -76,7 +77,23 @@ If no project is specified try to use current directory as a project.
76 ps_id = max(int(match.group(1)), ps_id) 77 ps_id = max(int(match.group(1)), ps_id)
77 to_get.append((project, chg_id, ps_id)) 78 to_get.append((project, chg_id, ps_id))
78 else: 79 else:
79 project = self.GetProjects([a])[0] 80 projects = self.GetProjects([a])
81 if len(projects) > 1:
82 # If the cwd is one of the projects, assume they want that.
83 try:
84 project = self.GetProjects('.')[0]
85 except NoSuchProjectError:
86 project = None
87 if project not in projects:
88 print('error: %s matches too many projects; please re-run inside '
89 'the project checkout.' % (a,), file=sys.stderr)
90 for project in projects:
91 print(' %s/ @ %s' % (project.relpath, project.revisionExpr),
92 file=sys.stderr)
93 sys.exit(1)
94 else:
95 project = projects[0]
96 print('Defaulting to cwd project', project.name)
80 return to_get 97 return to_get
81 98
82 def ValidateOptions(self, opt, args): 99 def ValidateOptions(self, opt, args):