# HG changeset patch # User liscju # Date 1455745501 -3600 # Node ID c7e8948627f330ab14d9ec53e1b3fe5039c259d1 # Parent 11c2f8af09c2942f021eb8850c2456f049c4ecde rebase: adds storing collapse message (issue4792) Before this patch collapse message wasn't stored so when you ran into the merge conflict while rebasing, running rebase --continue didn't remember the message and always opened editor to fill commit message. This patch adds saving collapse message in .hg/last-message.txt and restoring it later when needed. diff -r 11c2f8af09c2 -r c7e8948627f3 hgext/rebase.py --- a/hgext/rebase.py Mon Feb 22 17:53:19 2016 -0500 +++ b/hgext/rebase.py Wed Feb 17 22:45:01 2016 +0100 @@ -263,9 +263,11 @@ try: (originalwd, target, state, skipped, collapsef, keepf, keepbranchesf, external, activebookmark) = restorestatus(repo) + collapsemsg = restorecollapsemsg(repo) except error.RepoLookupError: if abortf: clearstatus(repo) + clearcollapsemsg(repo) repo.ui.warn(_('rebase aborted (no revision is removed,' ' only broken state is cleared)\n')) return 0 @@ -388,6 +390,7 @@ targetancestors) storestatus(repo, originalwd, target, state, collapsef, keepf, keepbranchesf, external, activebookmark) + storecollapsemsg(repo, collapsemsg) if len(repo[None].parents()) == 2: repo.ui.debug('resuming interrupted rebase\n') else: @@ -509,6 +512,7 @@ # active bookmark was divergent one and has been deleted activebookmark = None clearstatus(repo) + clearcollapsemsg(repo) ui.note(_("rebase completed\n")) util.unlinkpath(repo.sjoin('undo'), ignoremissing=True) @@ -846,6 +850,29 @@ bookmarks.deletedivergent(repo, [targetnode], k) marks.recordchange(tr) +def storecollapsemsg(repo, collapsemsg): + 'Store the collapse message to allow recovery' + collapsemsg = collapsemsg or '' + f = repo.vfs("last-message.txt", "w") + f.write("%s\n" % collapsemsg) + f.close() + +def clearcollapsemsg(repo): + 'Remove collapse message file' + util.unlinkpath(repo.join("last-message.txt"), ignoremissing=True) + +def restorecollapsemsg(repo): + 'Restore previously stored collapse message' + try: + f = repo.vfs("last-message.txt") + collapsemsg = f.readline().strip() + f.close() + except IOError as err: + if err.errno != errno.ENOENT: + raise + raise error.Abort(_('no rebase in progress')) + return collapsemsg + def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches, external, activebookmark): 'Store the current status to allow recovery' @@ -1005,6 +1032,7 @@ finally: clearstatus(repo) + clearcollapsemsg(repo) repo.ui.warn(_('rebase aborted\n')) return 0 diff -r 11c2f8af09c2 -r c7e8948627f3 tests/test-rebase-collapse.t --- a/tests/test-rebase-collapse.t Mon Feb 22 17:53:19 2016 -0500 +++ b/tests/test-rebase-collapse.t Wed Feb 17 22:45:01 2016 +0100 @@ -804,3 +804,52 @@ base $ cd .. + +Test that rebase --collapse will remember message after +running into merge conflict and invoking rebase --continue. + + $ hg init collapse_remember_message + $ cd collapse_remember_message + $ touch a + $ hg add a + $ hg commit -m "a" + $ echo "a-default" > a + $ hg commit -m "a-default" + $ hg update -r 0 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg branch dev + marked working directory as branch dev + (branches are permanent and global, did you want a bookmark?) + $ echo "a-dev" > a + $ hg commit -m "a-dev" + $ hg rebase --collapse -m "a-default-dev" -d 1 + rebasing 2:b8d8db2b242d "a-dev" (tip) + merging a + warning: conflicts while merging a! (edit, then use 'hg resolve --mark') + unresolved conflicts (see hg resolve, then hg rebase --continue) + [1] + $ rm a.orig + $ hg resolve --mark a + (no more unresolved files) + continue: hg rebase --continue + $ hg rebase --continue + rebasing 2:b8d8db2b242d "a-dev" (tip) + saved backup bundle to $TESTTMP/collapse_remember_message/.hg/strip-backup/b8d8db2b242d-f474c19a-backup.hg (glob) + $ hg log + changeset: 2:12bb766dceb1 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a-default-dev + + changeset: 1:3c8db56a44bc + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a-default + + changeset: 0:3903775176ed + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a + + $ cd ..