mq: avoid qnew committing everything on invalid paths (issue 803)
authorPatrick Mezard <pmezard@gmail.com>
Tue, 20 Nov 2007 14:31:58 +0100
changeset 5534 61c230f81068
parent 5527 0b3f910dfd17
child 5540 00b812ad67cb
child 5547 777996744942
mq: avoid qnew committing everything on invalid paths (issue 803) If paths are supplied but resolve to nothing, localrepo.commit() is called with an empty set and commits the whole dirstate. Avoid this by passing the match function to commit.
hgext/mq.py
tests/test-mq
tests/test-mq.out
--- a/hgext/mq.py	Fri Nov 09 20:21:35 2007 -0200
+++ b/hgext/mq.py	Tue Nov 20 14:31:58 2007 +0100
@@ -610,15 +610,14 @@
             m, a, r, d = repo.status(files=fns, match=match)[:4]
         else:
             m, a, r, d = self.check_localchanges(repo, force)
+            fns, match, anypats = cmdutil.matchpats(repo, m + a + r)
         commitfiles = m + a + r
         self.check_toppatch(repo)
         wlock = repo.wlock()
         try:
             insert = self.full_series_end()
-            if msg:
-                n = repo.commit(commitfiles, msg, force=True)
-            else:
-                n = repo.commit(commitfiles, "[mq]: %s" % patch, force=True)
+            commitmsg = msg and msg or ("[mq]: %s" % patch)
+            n = repo.commit(commitfiles, commitmsg, match=match, force=True)
             if n == None:
                 raise util.Abort(_("repo commit failed"))
             self.full_series[insert:insert] = [patch]
--- a/tests/test-mq	Fri Nov 09 20:21:35 2007 -0200
+++ b/tests/test-mq	Tue Nov 20 14:31:58 2007 +0100
@@ -84,6 +84,27 @@
 
 cd a
 
+echo a > somefile
+hg add somefile
+
+echo % qnew with uncommitted changes
+
+hg qnew uncommitted.patch
+hg st
+hg qseries
+
+echo '% qnew with uncommitted changes and missing file (issue 803)'
+
+hg qnew issue803.patch someotherfile 2>&1 | \
+    sed -e 's/someotherfile:.*/someotherfile: No such file or directory/'
+hg st
+hg qseries
+hg qpop -f
+hg qdel issue803.patch
+
+hg revert --no-backup somefile
+rm somefile
+
 echo % qnew -m
 
 hg qnew -m 'foo bar' test.patch
--- a/tests/test-mq.out	Fri Nov 09 20:21:35 2007 -0200
+++ b/tests/test-mq.out	Tue Nov 20 14:31:58 2007 +0100
@@ -83,6 +83,14 @@
   series:
 A
 B
+% qnew with uncommitted changes
+abort: local changes found, refresh first
+A somefile
+% qnew with uncommitted changes and missing file (issue 803)
+someotherfile: No such file or directory
+A somefile
+issue803.patch
+Patch queue now empty
 % qnew -m
 foo bar
 % qrefresh