Comments
Patch
new file mode 100644
@@ -0,0 +1,83 @@
+
+Create a python script to test merging with memctx
+
+ $ cat > memmerge.py << EOF
+ > #!/usr/bin/env python
+ > from mercurial import context, hg, merge, ui as uimod
+ > from mercurial.node import nullid
+ >
+ > ui = uimod.ui()
+ > myrepo = hg.repository(ui, '.')
+ >
+ > ctxa = myrepo.changectx(2)
+ > ctxb = myrepo.changectx(3)
+ > orig = myrepo['.']
+ >
+ > # build a memctx off of ctxa (but set parents to ctxa and ctxb)
+ > rctx = context.memctx(myrepo, [ctxa.node(), ctxb.node()], 'test merge',
+ > ctxa.files(), ctxa, user=ctxa.user(), date=ctxa.date(),
+ > extra=ctxa.extra())
+ >
+ > stats = merge.update(myrepo, ctxa.node(), True, True, False, ctxa.p1().node(), rctx=rctx)
+ >
+ > del rctx._status
+ > del rctx._manifest
+ >
+ > wlock = myrepo.wlock()
+ > try:
+ > node = myrepo.commitctx(rctx)
+ > myrepo.setparents(orig.node(), nullid)
+ > myrepo.dirstate.write()
+ > finally:
+ > wlock.release()
+ > EOF
+
+The test requires a repo with two heads
+
+ $ hg init main
+ $ cd main
+ $ echo line1 > a
+ $ hg commit -Am0
+ adding a
+ $ echo lineA > b
+ $ hg commit -Am1
+ adding b
+ $ echo line2 >> a
+ $ hg commit -Am2
+ $ hg update 1
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ echo lineB >> b
+ $ hg commit -Am3
+ created new head
+
+
+Merge with a dirty working directory
+
+ $ echo dirty >> b
+ $ python $TESTTMP/memmerge.py
+ $ hg log -pr tip
+ changeset: 4:d17d631aeace
+ tag: tip
+ parent: 2:fc28dc423489
+ parent: 3:c9ea6e4408ad
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: test merge
+
+ diff -r fc28dc423489 -r d17d631aeace b
+ --- a/b Thu Jan 01 00:00:00 1970 +0000
+ +++ b/b Thu Jan 01 00:00:00 1970 +0000
+ @@ -1,1 +1,2 @@
+ lineA
+ +lineB
+
+Make sure the directory is still dirty
+
+ $ hg diff --git --nodates
+ diff --git a/b b/b
+ --- a/b
+ +++ b/b
+ @@ -1,2 +1,3 @@
+ lineA
+ lineB
+ +dirty