[PATCH] (3/4) Removing an added file

Michael A Fetterman Michael.Fetterman at cl.cam.ac.uk
Sat Jun 18 23:50:01 UTC 2005


Here's an hg changeset that deals with "hg add"ing and then "hg remove"ing
a file without ever committing it.  Previously, this caused a python
exception
at commit time.

Test case included in the patch.


# HG changeset patch
# User maf46 at burn.cl.cam.ac.uk
# Node ID 53f5cd4ad79feed2c1789798eb3690bba3a639b6
# Parent  b836e1b2d09414b9bfde25ed648190b52a2c5030

Removing an added file

Removing a file that was "hg add"ed, but never committed, ought not
to cause an exception in python.

diff -r b836e1b2d094 -r 53f5cd4ad79f mercurial/hg.py
--- a/mercurial/hg.py   Sat Jun 18 17:02:47 2005
+++ b/mercurial/hg.py   Sat Jun 18 17:08:55 2005
@@ -706,6 +706,9 @@
             p = self.wjoin(f)
             if os.path.isfile(p):
                 self.ui.warn("%s still exists!\n" % f)
+            elif self.dirstate.state(f) == 'a':
+                self.ui.warn("%s never committed!\n" % f)
+                self.dirstate.forget(f)
             elif f not in self.dirstate:
                 self.ui.warn("%s not tracked!\n" % f)
             else:
diff -r b836e1b2d094 -r 53f5cd4ad79f tests/test-merge3
--- /dev/null   Sat Jun 18 17:02:47 2005
+++ b/tests/test-merge3 Sat Jun 18 17:08:55 2005
@@ -0,0 +1,10 @@
+#!/bin/sh -x
+
+hg init
+echo This is file a1 > a
+hg add a
+hg commit -t "commit #0" -d "0 0" -u user
+touch b
+hg add b
+rm b
+hg commit -A -t"comment #1" -d "0 0" -u user
diff -r b836e1b2d094 -r 53f5cd4ad79f tests/test-merge3.out
--- /dev/null   Sat Jun 18 17:02:47 2005
+++ b/tests/test-merge3.out     Sat Jun 18 17:08:55 2005
@@ -0,0 +1,9 @@
++ hg init
++ echo This is file a1
++ hg add a
++ hg commit -t 'commit #0' -d '0 0' -u user
++ touch b
++ hg add b
++ rm b
++ hg commit -A '-tcomment #1' -d '0 0' -u user
+b never committed!




More information about the Mercurial mailing list