changeset 21028:a0f437e2f5a9 stable

histedit: save manually edited commit message into ".hg/last-message.txt" Before this patch, manually edited commit message for "message" command in histedit-ing is not saved into ".hg/last-message.txt" until it is saved by "localrepository.savecommitmessage()" in "localrepository.commit()". This may lose such commit message, if unexpected exception is raised. This patch saves manually edited commit message for "message" comand in histedit-ing into ".hg/last-message.txt" just after user editing. This is the simplest implementation to fix on stable. Editing and saving commit message should be centralized into the framework of "localrepository.commit()" with "editor" argument in the future. This patch uses repository wrapping class for exception raising before saving commit message in "localrepository.commit()" easily and certainly, because such exception requires corner case condition.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Apr 2014 03:21:59 +0900
parents 469d949a7cb8
children 76f68595ff8e 564f55b25122
files hgext/histedit.py tests/test-histedit-edit.t
diffstat 2 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Mon Apr 07 14:18:10 2014 -0500
+++ b/hgext/histedit.py	Tue Apr 15 03:21:59 2014 +0900
@@ -398,6 +398,7 @@
             _('Fix up the change and run hg histedit --continue'))
     message = oldctx.description() + '\n'
     message = ui.edit(message, ui.username())
+    repo.savecommitmessage(message)
     commit = commitfuncfor(repo, oldctx)
     new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
                  extra=oldctx.extra())
--- a/tests/test-histedit-edit.t	Mon Apr 07 14:18:10 2014 -0500
+++ b/tests/test-histedit-edit.t	Tue Apr 15 03:21:59 2014 +0900
@@ -189,6 +189,49 @@
   
 
 modify the message
+
+check saving last-message.txt, at first
+
+  $ cat > $TESTTMP/commitfailure.py <<EOF
+  > from mercurial import util
+  > def reposetup(ui, repo):
+  >     class commitfailure(repo.__class__):
+  >         def commit(self, *args, **kwargs):
+  >             raise util.Abort('emulating unexpected abort')
+  >     repo.__class__ = commitfailure
+  > EOF
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > commitfailure = $TESTTMP/commitfailure.py
+  > EOF
+
+  $ cat > $TESTTMP/editor.sh <<EOF
+  > echo "==== before editing"
+  > cat \$1
+  > echo "===="
+  > echo "check saving last-message.txt" >> \$1
+  > EOF
+  $ rm -f .hg/last-message.txt
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit tip --commands - 2>&1 << EOF | fixbundle
+  > mess 1fd3b2fe7754 f
+  > EOF
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  ==== before editing
+  f
+  ====
+  abort: emulating unexpected abort
+  $ cat .hg/last-message.txt
+  f
+  check saving last-message.txt
+
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > commitfailure = !
+  > EOF
+  $ hg histedit --abort -q
+
+then, check "modify the message" itself
+
   $ hg histedit tip --commands - 2>&1 << EOF | fixbundle
   > mess 1fd3b2fe7754 f
   > EOF