[PATCH 1 of 2] status: add relative option flag (issue3835)

Sean Farley sean at farley.io
Wed Mar 25 00:46:56 CDT 2015


# HG changeset patch
# User Yung-Jin (Joey) Hu <yungjinhu at gmail.com>
# Date 1426736402 25200
#      Wed Mar 18 20:40:02 2015 -0700
# Node ID f9e43618a84b4ce1de23c8cdf22de5e9bcadafdd
# Parent  5b85a5bc5bbb9d8365953609d98e4dce7110e9b0
status: add relative option flag (issue3835)

Previously, you had to send the root of the repo to get the relative files of
the entire repo.

hg status $(hg root)

This had the downside of involking running mercurial twice. Instead let's just
add a flag and be done with it.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5686,10 +5686,12 @@ class httpservice(object):
     ('n', 'no-status', None, _('hide status prefix')),
     ('C', 'copies', None, _('show source of copied files')),
     ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
     ('', 'rev', [], _('show difference from revision'), _('REV')),
     ('', 'change', '', _('list the changed files of a revision'), _('REV')),
+    ('', 'relative', None,
+     ('list the changed files relative to working directory')),
     ] + walkopts + subrepoopts + formatteropts,
     _('[OPTION]... [FILE]...'),
     inferrepo=True)
 def status(ui, repo, *pats, **opts):
     """show changed files in the working directory
@@ -5757,11 +5759,17 @@ def status(ui, repo, *pats, **opts):
         node2 = scmutil.revsingle(repo, change, None).node()
         node1 = repo[node2].p1().node()
     else:
         node1, node2 = scmutil.revpair(repo, revs)
 
-    if pats:
+    relative = opts.get('relative')
+
+    if pats and relative:
+        msg = _('cannot specify path and --relative at the same time')
+        raise util.Abort(msg)
+
+    if pats or relative:
         cwd = repo.getcwd()
     else:
         cwd = ''
 
     if opts.get('print0'):
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -211,11 +211,11 @@ Show all commands + options
   merge: force, rev, preview, tool
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
   push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure
   remove: after, force, subrepos, include, exclude
   serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate
-  status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos, template
+  status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, relative, include, exclude, subrepos, template
   summary: remote
   update: clean, check, date, rev, tool
   addremove: similarity, subrepos, include, exclude, dry-run
   archive: no-decode, prefix, rev, type, subrepos, include, exclude
   backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -569,10 +569,11 @@ Test command without options
    -n --no-status           hide status prefix
    -C --copies              show source of copied files
    -0 --print0              end filenames with NUL, for use with xargs
       --rev REV [+]         show difference from revision
       --change REV          list the changed files of a revision
+      --relative            list the changed files relative to working directory
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns
    -S --subrepos            recurse into subrepositories
   
   (some details hidden, use --verbose to show complete help)
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -99,10 +99,22 @@ hg status . in repo root:
   $ hg status --cwd b/2 ..
   ? ../1/in_b_1
   ? in_b_2
   ? ../in_b
 
+test status relative flag
+
+  $ cd b/2
+  $ hg status --relative
+  ? ../../a/1/in_a_1
+  ? ../../a/in_a
+  ? ../1/in_b_1
+  ? in_b_2
+  ? ../in_b
+  ? ../../in_root
+  $ cd ../..
+
 combining patterns with root and patterns without a root works
 
   $ hg st a/in_a re:.*b$
   ? a/in_a
   ? b/in_b


More information about the Mercurial-devel mailing list