summaryrefslogtreecommitdiffstats
path: root/subcmds/list.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/list.py')
-rw-r--r--subcmds/list.py16
1 files changed, 13 insertions, 3 deletions
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
15import os
16
15from command import Command, MirrorSafeCommand 17from 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 = []