mq: add ".hgsubstate" to patch target list only if it is not listed up yet
If ".hgsubstate" is already listed up as one of commit targets, qnew
put diff of ".hgsubstate" twice into the patch file stored under
".hg/patches".
It causes rejections at applying such patches.
Other than the case like in added test script, this can also occur
when qnew is executed just after rolling back the committing updated
".hgsubstate".
This patch checks whether ".hgsubstate" is already listed up as one of
commit targets, and put it into the appropriate list only if it is not
listed up yet.
--- a/hgext/mq.py Thu Jul 12 14:20:34 2012 -0500
+++ b/hgext/mq.py Wed Jun 27 22:03:22 2012 +0900
@@ -1064,12 +1064,17 @@
if commitfiles:
parent = self.qparents(repo, n)
if inclsubs:
- if substatestate in 'a?':
- changes[1].append('.hgsubstate')
- elif substatestate in 'r':
- changes[2].append('.hgsubstate')
- else: # modified
- changes[0].append('.hgsubstate')
+ for files in changes[:3]:
+ if '.hgsubstate' in files:
+ break # already listed up
+ else:
+ # not yet listed up
+ if substatestate in 'a?':
+ changes[1].append('.hgsubstate')
+ elif substatestate in 'r':
+ changes[2].append('.hgsubstate')
+ else: # modified
+ changes[0].append('.hgsubstate')
chunks = patchmod.diff(repo, node1=parent, node2=n,
changes=changes, opts=diffopts)
for chunk in chunks:
--- a/tests/test-mq-subrepo.t Thu Jul 12 14:20:34 2012 -0500
+++ b/tests/test-mq-subrepo.t Wed Jun 27 22:03:22 2012 +0900
@@ -355,3 +355,63 @@
$ hg qnew 0.diff
$ cd ..
+
+check whether MQ operations can import updated .hgsubstate correctly
+both into 'revision' and 'patch file under .hg/patches':
+
+ $ hg init importing-hgsubstate
+ $ cd importing-hgsubstate
+
+ $ echo a > a
+ $ hg commit -u test -d '0 0' -Am '#0 in parent'
+ adding a
+ $ hg init sub
+ $ echo sa > sub/sa
+ $ hg -R sub commit -u test -d '0 0' -Am '#0 in sub'
+ adding sa
+ $ echo 'sub = sub' > .hgsub
+ $ touch .hgsubstate
+ $ hg add .hgsub .hgsubstate
+
+ $ hg qnew -u test -d '0 0' import-at-qnew
+ $ hg -R sub parents --template '{node} sub\n'
+ b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+ $ cat .hgsubstate
+ b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+ $ hg diff -c tip
+ diff -r f499373e340c -r b20ffac88564 .hgsub
+ --- /dev/null
+ +++ b/.hgsub
+ @@ -0,0 +1,1 @@
+ +sub = sub
+ diff -r f499373e340c -r b20ffac88564 .hgsubstate
+ --- /dev/null
+ +++ b/.hgsubstate
+ @@ -0,0 +1,1 @@
+ +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+ $ cat .hg/patches/import-at-qnew
+ # HG changeset patch
+ # Parent f499373e340cdca5d01dee904aeb42dd2a325e71
+ # User test
+ # Date 0 0
+
+ diff -r f499373e340c -r b20ffac88564 .hgsub
+ --- /dev/null
+ +++ b/.hgsub
+ @@ -0,0 +1,1 @@
+ +sub = sub
+ diff -r f499373e340c -r b20ffac88564 .hgsubstate
+ --- /dev/null
+ +++ b/.hgsubstate
+ @@ -0,0 +1,1 @@
+ +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+ $ hg qpop
+ popping import-at-qnew
+ patch queue now empty
+ $ hg qpush
+ applying import-at-qnew
+ now at: import-at-qnew
+
+ $ cd ..
+
+ $ cd ..