changeset 47202:b338d831d18c

templates: fix `revset('parents()') % ...` in amend message template I don't understand why, but putting `revset('parents()') % {desc}` in the commit message template for amend resulted in a crash because `memctx.hex()` did `hex(self.node())` and its node was None. This patch fixes that. Martin von Zweigbergk <martinvonz@google.com> Differential Revision: https://phab.mercurial-scm.org/D10707
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 11 May 2021 12:22:26 -0700
parents 294a0aa51b8b
children 1249eb9cc332
files mercurial/context.py tests/test-commit-amend.t
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Thu Apr 15 19:54:03 2021 +0200
+++ b/mercurial/context.py	Tue May 11 12:22:26 2021 -0700
@@ -1392,6 +1392,9 @@
     def __bytes__(self):
         return bytes(self._parents[0]) + b"+"
 
+    def hex(self):
+        self._repo.nodeconstants.wdirhex
+
     __str__ = encoding.strmethod(__bytes__)
 
     def __nonzero__(self):
--- a/tests/test-commit-amend.t	Thu Apr 15 19:54:03 2021 +0200
+++ b/tests/test-commit-amend.t	Tue May 11 12:22:26 2021 -0700
@@ -957,6 +957,7 @@
   $ cat >> .hg/hgrc <<EOF
   > [committemplate]
   > changeset.commit.amend = {desc}\n
+  >     HG: {revset('parents()') % 'parent: {desc|firstline}\n'}
   >     HG: M: {file_mods}
   >     HG: A: {file_adds}
   >     HG: R: {file_dels}
@@ -971,6 +972,8 @@
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo"
   expecting diff of foo
   
+  HG: parent: editor should be suppressed
+  
   HG: M: 
   HG: A: foo
   HG: R: 
@@ -985,6 +988,8 @@
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo and y"
   expecting diff of foo and y
   
+  HG: parent: expecting diff of foo
+  
   HG: M: 
   HG: A: foo y
   HG: R: 
@@ -1003,6 +1008,8 @@
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo and y"
   expecting diff of a, foo and y
   
+  HG: parent: expecting diff of foo and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a
@@ -1027,6 +1034,8 @@
   $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo, x and y"
   expecting diff of a, foo, x and y
   
+  HG: parent: expecting diff of a, foo and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a x
@@ -1058,6 +1067,8 @@
   $ HGEDITOR=cat hg commit --amend -e -m "cc should be excluded" -X cc
   cc should be excluded
   
+  HG: parent: expecting diff of a, foo, x and y
+  
   HG: M: 
   HG: A: foo y
   HG: R: a x