[PATCH] commit: added strict option

Henri Wiechers hwiechers at gmail.com
Thu Jun 4 00:33:26 CDT 2009


# HG changeset patch
# User Henri Wiechers <hwiechers at gmail.com>
# Date 1244092523 -7200
# Node ID 2a645182beb43e8ecf73541f405a084ff390d6c8
# Parent  dd3ebf81af433e37d301b3093f7e151bb52e01f8
commit: added strict option

The strict option will cause the commit to abort if the working directory
contains unknown files.

diff -r dd3ebf81af43 -r 2a645182beb4 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Wed Jun 03 17:12:48 2009 -0500
+++ b/mercurial/cmdutil.py	Thu Jun 04 07:15:23 2009 +0200
@@ -1194,6 +1194,12 @@
     if opts.get('addremove'):
         addremove(repo, pats, opts)
 
+    if opts.get('strict'):
+        status = repo.status(match=match(repo, pats, opts), unknown=True)
+        unknowns = status[4]
+        if unknowns:
+            raise util.Abort(_('unknown files'))
+
     return commitfunc(ui, repo, message, match(repo, pats, opts), opts)
 
 def commiteditor(repo, ctx):
diff -r dd3ebf81af43 -r 2a645182beb4 mercurial/commands.py
--- a/mercurial/commands.py	Wed Jun 03 17:12:48 2009 -0500
+++ b/mercurial/commands.py	Thu Jun 04 07:15:23 2009 +0200
@@ -3169,6 +3169,8 @@
         (commit,
          [('A', 'addremove', None,
            _('mark new/missing files as added/removed before committing')),
+          ('', 'strict', None,
+           _('abort if the working directory contains unknown files')),
           ('', 'close-branch', None,
            _('mark a branch as closed, hiding it from the branch list')),
          ] + walkopts + commitopts + commitopts2,
diff -r dd3ebf81af43 -r 2a645182beb4 tests/test-commit
--- a/tests/test-commit	Wed Jun 03 17:12:48 2009 -0500
+++ b/tests/test-commit	Thu Jun 04 07:15:23 2009 +0200
@@ -123,4 +123,34 @@
 HGEDITOR=cat hg ci -A
 cd ..
 
+echo % test commit strict
+hg init strict
+cd strict
+
+echo a > a
+hg add a
+echo unknown > unknown
+echo % should fail because of unknown
+hg ci --strict -ma
+
+echo % should succeed because unknown is excluded
+hg ci --strict -ma -X unknown
+
+echo b > b
+hg add b
+echo % should succeed because unknown is not included
+hg ci --strict -mb -I b
+
+echo c > c
+hg add c
+echo % should succeed because unknown is not specified in files
+hg ci --strict -mc c
+
+echo d > d
+hg add d
+echo % should succeed and commit unknown because addremove takes precedence
+hg ci --strict -md --addremove
+hg status -c unknown
+cd ..
+
 exit 0
diff -r dd3ebf81af43 -r 2a645182beb4 tests/test-commit.out
--- a/tests/test-commit.out	Wed Jun 03 17:12:48 2009 -0500
+++ b/tests/test-commit.out	Thu Jun 04 07:15:23 2009 +0200
@@ -115,3 +115,12 @@
 HG: changed changed
 HG: removed removed
 abort: empty commit message
+% test commit strict
+% should fail because of unknown
+abort: unknown files
+% should succeed because unknown is excluded
+% should succeed because unknown is not included
+% should succeed because unknown is not specified in files
+% should succeed and commit unknown because addremove takes precedence
+adding unknown
+C unknown
diff -r dd3ebf81af43 -r 2a645182beb4 tests/test-debugcomplete.out
--- a/tests/test-debugcomplete.out	Wed Jun 03 17:12:48 2009 -0500
+++ b/tests/test-debugcomplete.out	Thu Jun 04 07:15:23 2009 +0200
@@ -163,7 +163,7 @@
 add: include, exclude, dry-run
 annotate: rev, follow, text, user, date, number, changeset, line-number, include, exclude
 clone: noupdate, rev, pull, uncompressed, ssh, remotecmd
-commit: addremove, close-branch, include, exclude, message, logfile, date, user
+commit: addremove, strict, close-branch, include, exclude, message, logfile, date, user
 diff: rev, change, text, git, nodates, show-function, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, include, exclude
 export: output, switch-parent, text, git, nodates
 init: ssh, remotecmd
diff -r dd3ebf81af43 -r 2a645182beb4 tests/test-record.out
--- a/tests/test-record.out	Wed Jun 03 17:12:48 2009 -0500
+++ b/tests/test-record.out	Thu Jun 04 07:15:23 2009 +0200
@@ -29,6 +29,8 @@
 
  -A --addremove     mark new/missing files as added/removed before
                     committing
+    --strict        abort if the working directory contains unknown
+                    files
     --close-branch  mark a branch as closed, hiding it from the branch
                     list
  -I --include       include names matching the given patterns


More information about the Mercurial-devel mailing list