diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2715,9 +2715,14 @@ def commitforceeditor(repo, ctx, subs, f # run editor in the repository root olddir = os.getcwd() os.chdir(repo.root) + + # make in-memory changes visible to external process + tr = repo.currenttransaction() + repo.dirstate.write(tr) + pending = tr and tr.writepending() and repo.root + editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(), - editform=editform) - + editform=editform, pending=pending) text = re.sub("(?m)^HG:.*(\n|$)", "", editortext) os.chdir(olddir) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -835,7 +835,8 @@ class ui(object): if self.debugflag: opts['label'] = opts.get('label', '') + ' ui.debug' self.write(*msg, **opts) - def edit(self, text, user, extra=None, editform=None): + + def edit(self, text, user, extra=None, editform=None, pending=None): if extra is None: extra = {} (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt", @@ -854,6 +855,8 @@ class ui(object): break if editform: environ.update({'HGEDITFORM': editform}) + if pending: + environ.update({'HG_PENDING': pending}) editor = self.geteditor() diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t --- a/tests/test-commit-amend.t +++ b/tests/test-commit-amend.t @@ -19,7 +19,7 @@ Refuse to amend public csets: Nothing to amend: - $ hg ci --amend + $ hg ci --amend -m 'base1' nothing changed [1] diff --git a/tests/test-import.t b/tests/test-import.t --- a/tests/test-import.t +++ b/tests/test-import.t @@ -447,6 +447,92 @@ page for detail). $ hg --cwd b parents --template 'parent: {rev}\n' parent: 1 + $ hg --cwd b update -q -C 0 + $ hg --cwd b --config extensions.strip= strip -q 1 + +Test visibility of in-memory distate changes inside transaction to +external process + + $ echo foo > a/foo + $ hg --cwd a commit -A -m 'adding foo' foo + $ hg --cwd a export -o '../patch%R' 3 + + $ cat > $TESTTMP/checkvisibility.sh < echo "====" + > hg parents --template "VISIBLE {rev}:{node|short}\n" + > hg status -amr + > # test that pending changes are hidden + > unset HG_PENDING + > hg parents --template "ACTUAL {rev}:{node|short}\n" + > hg status -amr + > echo "====" + > EOF + +== test visibility to external editor + + $ (cd b && sh "$TESTTMP/checkvisibility.sh") + ==== + VISIBLE 0:80971e65b431 + ACTUAL 0:80971e65b431 + ==== + + $ HGEDITOR="sh $TESTTMP/checkvisibility.sh" hg --cwd b import -v --edit ../patch1 ../patch2 ../patch3 + applying ../patch1 + patching file a + ==== + VISIBLE 0:80971e65b431 + M a + ACTUAL 0:80971e65b431 + M a + ==== + committing files: + a + committing manifest + committing changelog + created 1d4bd90af0e4 + applying ../patch2 + patching file a + ==== + VISIBLE 1:1d4bd90af0e4 + M a + ACTUAL 0:80971e65b431 + M a + ==== + committing files: + a + committing manifest + committing changelog + created 6d019af21222 + applying ../patch3 + patching file foo + adding foo + ==== + VISIBLE 2:6d019af21222 + A foo + ACTUAL 0:80971e65b431 + M a + ==== + committing files: + foo + committing manifest + committing changelog + created 55e3f75b2378 + + $ hg --cwd b rollback -q + +(content of file "a" is already changed and it should be recognized as +"M", even though dirstate is restored to one before "hg import") + + $ (cd b && sh "$TESTTMP/checkvisibility.sh") + ==== + VISIBLE 0:80971e65b431 + M a + ACTUAL 0:80971e65b431 + M a + ==== + $ hg --cwd b revert --no-backup a + $ rm -f b/foo + $ rm -r b diff --git a/tests/test-mq-qrefresh-replace-log-message.t b/tests/test-mq-qrefresh-replace-log-message.t --- a/tests/test-mq-qrefresh-replace-log-message.t +++ b/tests/test-mq-qrefresh-replace-log-message.t @@ -2,6 +2,13 @@ Environment setup for MQ $ echo "[extensions]" >> $HGRCPATH $ echo "mq=" >> $HGRCPATH + $ cat >> $HGRCPATH < [defaults] + > # explicit date to commit with fixed hashid + > qnew = -d "0 0" + > qrefresh = -d "0 0" + > qfold = -d "0 0" + > EOF $ hg init $ hg qinit @@ -191,3 +198,47 @@ Test saving last-message.txt: test saving last-message.txt + +Test visibility of in-memory distate changes outside transaction to +external process + + $ cat > $TESTTMP/checkvisibility.sh < echo "====" + > hg parents --template "{rev}:{node|short}\n" + > hg status -arm + > echo "====" + > EOF + +== test visibility to external editor + + $ hg update -C -q first-patch + $ rm -f file2 + $ hg qpush -q second-patch --config hooks.pretxncommit.unexpectedabort= + now at: second-patch + $ echo bbbb >> file2 + + $ sh "$TESTTMP/checkvisibility.sh" + ==== + 1:e30108269082 + M file2 + ==== + + $ HGEDITOR='sh "$TESTTMP/checkvisibility.sh"' hg qrefresh -e + ==== + 0:25e397dabed2 + A file2 + ==== + transaction abort! + rollback completed + note: commit message saved in .hg/last-message.txt + refresh interrupted while patch was popped! (revert --all, qpush to recover) + abort: pretxncommit.unexpectedabort hook exited with status 1 + [255] + +(rebuilding at failure of qrefresh bases on rev #0, and it causes +dropping status of "file2") + + $ sh "$TESTTMP/checkvisibility.sh" + ==== + 0:25e397dabed2 + ====