subrepo: Update .hgsubstate in case of deleted subrepo stable
authorSaint Germain <saintger@gmail.com>
Mon, 22 Feb 2010 01:19:59 +0100
branchstable
changeset 10522 b07d487009b2
parent 10521 bde1bb250fc2
child 10523 4bab7c3db4e1
subrepo: Update .hgsubstate in case of deleted subrepo When a subrepo is deleted from .hgsub, it also needs to be removed from .hgsubstate. Previous code was updating .hgsubstate only in case of newly or modified subrepo.
mercurial/localrepo.py
tests/test-subrepo
tests/test-subrepo.out
--- a/mercurial/localrepo.py	Sun Feb 21 22:16:35 2010 +0100
+++ b/mercurial/localrepo.py	Mon Feb 22 01:19:59 2010 +0100
@@ -787,10 +787,14 @@
 
             # check subrepos
             subs = []
+            removedsubs = set()
+            for p in wctx.parents():
+                removedsubs.update(s for s in p.substate if match(s))
             for s in wctx.substate:
+                removedsubs.discard(s)
                 if match(s) and wctx.sub(s).dirty():
                     subs.append(s)
-            if subs and '.hgsubstate' not in changes[0]:
+            if (subs or removedsubs) and '.hgsubstate' not in changes[0]:
                 changes[0].insert(0, '.hgsubstate')
 
             # make sure all explicit patterns are matched
@@ -830,7 +834,7 @@
             edited = (text != cctx._text)
 
             # commit subs
-            if subs:
+            if subs or removedsubs:
                 state = wctx.substate.copy()
                 for s in subs:
                     self.ui.status(_('committing subrepository %s\n') % s)
--- a/tests/test-subrepo	Sun Feb 21 22:16:35 2010 +0100
+++ b/tests/test-subrepo	Mon Feb 22 01:19:59 2010 +0100
@@ -162,6 +162,28 @@
 hg merge 4    # try to merge default into br again
 cd ..
 
+echo % test subrepo delete from .hgsubstate
+hg init testdelete
+mkdir testdelete/nested testdelete/nested2
+hg init testdelete/nested
+hg init testdelete/nested2
+echo test > testdelete/nested/foo
+echo test > testdelete/nested2/foo
+hg -R testdelete/nested add
+hg -R testdelete/nested2 add
+hg -R testdelete/nested ci -m test
+hg -R testdelete/nested2 ci -m test
+echo nested = nested > testdelete/.hgsub
+echo nested2 = nested2 >> testdelete/.hgsub
+hg -R testdelete add
+hg -R testdelete ci -m "nested 1 & 2 added"
+echo nested = nested > testdelete/.hgsub
+hg -R testdelete ci -m "nested 2 deleted"
+cat testdelete/.hgsubstate | sed "s:.* ::"
+hg -R testdelete remove testdelete/.hgsub
+hg -R testdelete ci -m ".hgsub deleted"
+cat testdelete/.hgsubstate
+
 echo % test repository cloning
 mkdir mercurial mercurial2
 hg init nested_absolute
--- a/tests/test-subrepo.out	Sun Feb 21 22:16:35 2010 +0100
+++ b/tests/test-subrepo.out	Mon Feb 22 01:19:59 2010 +0100
@@ -247,6 +247,13 @@
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
+% test subrepo delete from .hgsubstate
+adding testdelete/nested/foo
+adding testdelete/nested2/foo
+adding testdelete/.hgsub
+committing subrepository nested2
+committing subrepository nested
+nested
 % test repository cloning
 adding nested_absolute/foo
 adding nested_relative/foo2