amend: allow aborting an `amend --patch` by saving an empty file (issue5925)
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 08 Jul 2018 22:52:33 +0530
changeset 3877 96bbea985b25
parent 3876 c464abfd7f9d
child 3878 dc2b53b3573f
amend: allow aborting an `amend --patch` by saving an empty file (issue5925) This patch fixes issue5925 by allow aborting a `hg amend --patch` call by saving an empty patch file. This is similar to aborting of `hg amend` when commit message is empty. Test changes demonstrate the fix.
hgext3rd/evolve/cmdrewrite.py
tests/test-amend-patch.t
--- a/hgext3rd/evolve/cmdrewrite.py	Sun Jul 08 22:50:16 2018 +0530
+++ b/hgext3rd/evolve/cmdrewrite.py	Sun Jul 08 22:52:33 2018 +0530
@@ -207,6 +207,8 @@
                     afp.write(chunk)
 
         user_patch = afp.getvalue()
+        if not user_patch:
+            raise error.Abort(_("empty patch file, amend aborted"))
         if user_patch == previous_patch:
             raise error.Abort(_("patch unchanged"))
         afp.seek(0)
--- a/tests/test-amend-patch.t	Sun Jul 08 22:50:16 2018 +0530
+++ b/tests/test-amend-patch.t	Sun Jul 08 22:52:33 2018 +0530
@@ -1167,6 +1167,8 @@
   > EOF
 
   $ HGEDITOR="sh ./editor.sh" hg amend --patch
+  abort: empty patch file, amend aborted
+  [255]
 
   $ hg exp
   # HG changeset patch
@@ -1174,17 +1176,26 @@
   # Date 123456 1200
   #      Fri Jan 02 09:57:36 1970 -0020
   # Branch stable
-  # Node ID 958c723d2247bedf32c155b7976e79b82332c02e
-  # Parent  0000000000000000000000000000000000000000
+  # Node ID f14ecd7121e63915ac93edbad7f60f605e62dd52
+  # Parent  fc57c20be380f2878f4db139dad66d6cfb42ec62
+  I am a message which is testing change of message
   
-  
+  diff --git a/a b/a
+  new file mode 100755
+  --- /dev/null
+  +++ b/a
+  @@ -0,0 +1,3 @@
+  +Gello
+  +Kello
+  +betto
 
   $ hg parents
-  changeset:   19:958c723d2247
+  changeset:   18:f14ecd7121e6
   branch:      stable
   bookmark:    foo
   tag:         tip
-  parent:      -1:000000000000
+  parent:      3:fc57c20be380
   user:        RandomUser
   date:        Fri Jan 02 09:57:36 1970 -0020
+  summary:     I am a message which is testing change of message