diff options
author | Mike Frysinger <vapier@google.com> | 2021-07-26 15:28:01 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-07-27 06:20:52 +0000 |
commit | 5467185db0fe31558dbb57f08135c316861a86b1 (patch) | |
tree | dff80d322ce97145fe8f55cf4bd5b3b1505a820d | |
parent | b380322174c9b67da99ce743ff49382bab5cf351 (diff) | |
download | git-repo-5467185db0fe31558dbb57f08135c316861a86b1.tar.gz |
list: add a --relative-to option
The current list output only shows project paths relative to the
root of the repo client checkout. It can be helpful to also get
a listing of paths based on other paths (e.g. the current working
directory), so add an option to repo list to support that. We'll
leverage this in bash completion to support completing projects by
their local paths and not just remote names.
Bug: https://crbug.com/gerrit/14797
Change-Id: Ia2b35d18c890217768448118b003874a1016efd4
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312904
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | completion.bash | 1 | ||||
-rw-r--r-- | man/repo-list.1 | 12 | ||||
-rw-r--r-- | subcmds/list.py | 16 |
3 files changed, 22 insertions, 7 deletions
diff --git a/completion.bash b/completion.bash index 04347ce3..6a5bfe1c 100644 --- a/completion.bash +++ b/completion.bash | |||
@@ -37,6 +37,7 @@ __complete_repo_list_branches() { | |||
37 | __complete_repo_list_projects() { | 37 | __complete_repo_list_projects() { |
38 | local repo=${COMP_WORDS[0]} | 38 | local repo=${COMP_WORDS[0]} |
39 | "${repo}" list -n 2>/dev/null | 39 | "${repo}" list -n 2>/dev/null |
40 | "${repo}" list -p --relative-to=. 2>/dev/null | ||
40 | } | 41 | } |
41 | 42 | ||
42 | # Complete the repo <command> argument. | 43 | # Complete the repo <command> argument. |
diff --git a/man/repo-list.1 b/man/repo-list.1 index a86315ae..7f85e612 100644 --- a/man/repo-list.1 +++ b/man/repo-list.1 | |||
@@ -27,15 +27,19 @@ project is in | |||
27 | \fB\-a\fR, \fB\-\-all\fR | 27 | \fB\-a\fR, \fB\-\-all\fR |
28 | show projects regardless of checkout state | 28 | show projects regardless of checkout state |
29 | .TP | 29 | .TP |
30 | \fB\-f\fR, \fB\-\-fullpath\fR | ||
31 | display the full work tree path instead of the | ||
32 | relative path | ||
33 | .TP | ||
34 | \fB\-n\fR, \fB\-\-name\-only\fR | 30 | \fB\-n\fR, \fB\-\-name\-only\fR |
35 | display only the name of the repository | 31 | display only the name of the repository |
36 | .TP | 32 | .TP |
37 | \fB\-p\fR, \fB\-\-path\-only\fR | 33 | \fB\-p\fR, \fB\-\-path\-only\fR |
38 | display only the path of the repository | 34 | display only the path of the repository |
35 | .TP | ||
36 | \fB\-f\fR, \fB\-\-fullpath\fR | ||
37 | display the full work tree path instead of the | ||
38 | relative path | ||
39 | .TP | ||
40 | \fB\-\-relative\-to\fR=\fI\,PATH\/\fR | ||
41 | display paths relative to this one (default: top of | ||
42 | repo client checkout) | ||
39 | .SS Logging options: | 43 | .SS Logging options: |
40 | .TP | 44 | .TP |
41 | \fB\-v\fR, \fB\-\-verbose\fR | 45 | \fB\-v\fR, \fB\-\-verbose\fR |
diff --git a/subcmds/list.py b/subcmds/list.py index 8d0c5640..6adf85b7 100644 --- a/subcmds/list.py +++ b/subcmds/list.py | |||
@@ -12,6 +12,8 @@ | |||
12 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import os | ||
16 | |||
15 | from command import Command, MirrorSafeCommand | 17 | from command import Command, MirrorSafeCommand |
16 | 18 | ||
17 | 19 | ||
@@ -43,20 +45,26 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
43 | p.add_option('-a', '--all', | 45 | p.add_option('-a', '--all', |
44 | action='store_true', | 46 | action='store_true', |
45 | help='show projects regardless of checkout state') | 47 | help='show projects regardless of checkout state') |
46 | p.add_option('-f', '--fullpath', | ||
47 | dest='fullpath', action='store_true', | ||
48 | help='display the full work tree path instead of the relative path') | ||
49 | p.add_option('-n', '--name-only', | 48 | p.add_option('-n', '--name-only', |
50 | dest='name_only', action='store_true', | 49 | dest='name_only', action='store_true', |
51 | help='display only the name of the repository') | 50 | help='display only the name of the repository') |
52 | p.add_option('-p', '--path-only', | 51 | p.add_option('-p', '--path-only', |
53 | dest='path_only', action='store_true', | 52 | dest='path_only', action='store_true', |
54 | help='display only the path of the repository') | 53 | help='display only the path of the repository') |
54 | p.add_option('-f', '--fullpath', | ||
55 | dest='fullpath', action='store_true', | ||
56 | help='display the full work tree path instead of the relative path') | ||
57 | p.add_option('--relative-to', metavar='PATH', | ||
58 | help='display paths relative to this one (default: top of repo client checkout)') | ||
55 | 59 | ||
56 | def ValidateOptions(self, opt, args): | 60 | def ValidateOptions(self, opt, args): |
57 | if opt.fullpath and opt.name_only: | 61 | if opt.fullpath and opt.name_only: |
58 | self.OptionParser.error('cannot combine -f and -n') | 62 | self.OptionParser.error('cannot combine -f and -n') |
59 | 63 | ||
64 | # Resolve any symlinks so the output is stable. | ||
65 | if opt.relative_to: | ||
66 | opt.relative_to = os.path.realpath(opt.relative_to) | ||
67 | |||
60 | def Execute(self, opt, args): | 68 | def Execute(self, opt, args): |
61 | """List all projects and the associated directories. | 69 | """List all projects and the associated directories. |
62 | 70 | ||
@@ -76,6 +84,8 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
76 | def _getpath(x): | 84 | def _getpath(x): |
77 | if opt.fullpath: | 85 | if opt.fullpath: |
78 | return x.worktree | 86 | return x.worktree |
87 | if opt.relative_to: | ||
88 | return os.path.relpath(x.worktree, opt.relative_to) | ||
79 | return x.relpath | 89 | return x.relpath |
80 | 90 | ||
81 | lines = [] | 91 | lines = [] |