Issue1089

Title 'hg rm dir/*; hg ci dir' won't work
Priority bug Status resolved
Superseder Nosy List djc, mg, muntyan, tonfa
Assigned To Topics patch

Created on 2008-04-16.02:20:38 by muntyan, last changed 2008-09-15.08:09:20 by djc.

Messages
msg7131 (view) Author: djc Date: 2008-09-15.08:09:20
In main, resolving.
msg6930 (view) Author: djc Date: 2008-09-03.17:27:06
This should be fixed in 2268edff1bec, now in crew.
msg6926 (view) Author: tonfa Date: 2008-09-03.00:45:08
# HG changeset patch
# User Benoit Boissinot <benoit.boissinot@ens-lyon.org>
# Date 1220401645 -7200
# Node ID 2268edff1bec20c1f3ee4bdee43275a216287bc8
# Parent  a3fd4aa154afff901779639df0963e4e2848b7dd
allow committing a removed directory

fix issue1089

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1155,6 +1155,12 @@
         modified, added, removed = repo.status(match=m)[:3]
         files = util.sort(modified + added + removed)
         slist = None
+
+        def is_dir(f):
+            name = f + '/'
+            i = bisect.bisect(files, name)
+            return i < len(files) and files[i].startswith(name)
+
         for f in m.files():
             if f == '.':
                 continue
@@ -1164,11 +1170,11 @@
                 try:
                     mode = os.lstat(rf)[stat.ST_MODE]
                 except OSError:
+                    if is_dir(f): # deleted directory ?
+                        continue
                     raise util.Abort(_("file %s not found!") % rel)
                 if stat.S_ISDIR(mode):
-                    name = f + '/'
-                    i = bisect.bisect(files, name)
-                    if i >= len(files) or not files[i].startswith(name):
+                    if not is_dir(f):
                         raise util.Abort(_("no match under directory %s!")
                                          % rel)
                 elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)):
diff --git a/tests/test-issue1089 b/tests/test-issue1089
new file mode 100755
--- /dev/null
+++ b/tests/test-issue1089
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+hg init a
+cd a
+mkdir a
+echo a > a/b
+hg ci -Am m
+hg rm a
+hg ci -m m a
+
+mkdir a b
+echo a > a/b
+hg ci -Am m
+hg rm a
+cd b
+# relative delete
+hg ci -m m ../a
diff --git a/tests/test-issue1089.out b/tests/test-issue1089.out
new file mode 100644
--- /dev/null
+++ b/tests/test-issue1089.out
@@ -0,0 +1,4 @@
+adding a/b
+removing a/b
+adding a/b
+removing a/b
msg6501 (view) Author: mg Date: 2008-07-11.21:15:17
Mercurial does not version directories. You can either do a

  hg commit

or mention the removed files directly like

  hg commit foo/file1 foo/file2

or maybe like this if these are the only files you have scheduled for removal:

  hg commit $(hg stat -n -r)
msg5909 (view) Author: muntyan Date: 2008-04-16.02:20:37
'hg ci directory' requires some files to be left in that directory, otherwise
mercurial says "abort: file foo not found!". This makes it pretty hard to remove
a directory.

test$ hg init
test$ mkdir foo
test$ touch foo/file1 foo/file2
test$ hg add foo; hg ci -m 1
adding foo/file1
adding foo/file2
test$ hg rm foo
removing foo/file1
removing foo/file2
test$ hg ci foo
abort: file foo not found!
History
Date User Action Args
2008-09-15 08:09:20djcsetstatus: testing -> resolved
nosy: tonfa, muntyan, mg, djc
messages: + msg7131
2008-09-03 17:27:06djcsetstatus: chatting -> testing
nosy: tonfa, muntyan, mg, djc
messages: + msg6930
2008-09-03 00:45:08tonfasettopic: + patch
nosy: tonfa, muntyan, mg, djc
messages: + msg6926
2008-09-03 00:36:23tonfasetnosy: + tonfa
2008-07-11 21:15:17mgsetstatus: unread -> chatting
nosy: + mg
messages: + msg6501
2008-04-16 05:29:03djcsetnosy: + djc
2008-04-16 02:20:38muntyancreate