changeset 17130:0a48f3d54543

histedit: don't crash if the result of fixing up a fold is empty
author Augie Fackler <raf@durin42.com>
date Fri, 06 Jul 2012 11:39:02 -0500
parents ead4eb5b03c9
children 4fb2d3d16743
files hgext/histedit.py tests/test-histedit-fold.t
diffstat 2 files changed, 80 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Fri Jul 06 11:06:57 2012 -0500
+++ b/hgext/histedit.py	Fri Jul 06 11:39:02 2012 -0500
@@ -307,7 +307,11 @@
             new = repo.commit(text=message, user=oldctx.user(),
                               date=oldctx.date(), extra=oldctx.extra())
 
-        if action in ('f', 'fold'):
+        # If we're resuming a fold and we have new changes, mark the
+        # replacements and finish the fold. If not, it's more like a
+        # drop of the changesets that disappeared, and we can skip
+        # this step.
+        if action in ('f', 'fold') and (new or newchildren):
             if new:
                 tmpnodes.append(new)
             else:
--- a/tests/test-histedit-fold.t	Fri Jul 06 11:06:57 2012 -0500
+++ b/tests/test-histedit-fold.t	Fri Jul 06 11:39:02 2012 -0500
@@ -108,3 +108,78 @@
   f
 
   $ cd ..
+
+folding and creating no new change doesn't break:
+  $ mkdir fold-to-empty-test
+  $ cd fold-to-empty-test
+  $ hg init
+  $ printf "1\n2\n3\n" > file
+  $ hg add file
+  $ hg commit -m '1+2+3'
+  $ echo 4 >> file
+  $ hg commit -m '+4'
+  $ echo 5 >> file
+  $ hg commit -m '+5'
+  $ echo 6 >> file
+  $ hg commit -m '+6'
+  $ hg log --graph
+  @  changeset:   3:251d831eeec5
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     +6
+  |
+  o  changeset:   2:888f9082bf99
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     +5
+  |
+  o  changeset:   1:617f94f13c0f
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     +4
+  |
+  o  changeset:   0:0189ba417d34
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     1+2+3
+  
+
+  $ cat > editor.py <<EOF
+  > import re, sys
+  > rules = sys.argv[1]
+  > data = open(rules).read()
+  > data = re.sub(r'pick ([0-9a-f]{12} 2 \+5)', r'drop \1', data)
+  > data = re.sub(r'pick ([0-9a-f]{12} 2 \+6)', r'fold \1', data)
+  > open(rules, 'w').write(data)
+  > EOF
+
+  $ HGEDITOR='python editor.py' hg histedit 1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  patching file file
+  Hunk #1 FAILED at 2
+  1 out of 1 hunks FAILED -- saving rejects to file file.rej
+  abort: Fix up the change and run hg histedit --continue
+  [255]
+There were conflicts, but we'll continue without resolving. This
+should effectively drop the changes from +6.
+  $ hg status
+  ? editor.py
+  ? file.rej
+  $ hg histedit --continue
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/*-backup.hg (glob)
+  $ hg log --graph
+  @  changeset:   1:617f94f13c0f
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     +4
+  |
+  o  changeset:   0:0189ba417d34
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     1+2+3
+  
+
+  $ cd ..