Commits

Anonymous committed b15910e

Fails when patch starter lines are removed from file

  • Participants
  • Parent commits a13785d

Comments (0)

Files changed (2)

File editcommitmsgs.py

 
     editedmessages = ui.edit(allmessages, ui.username)
     if editedmessages != allmessages:
-        commitmessages = parsemessage(editedmessages)
-        savecommitcomments(ui, repo, mq, appliedbefore, commitmessages)
-
-    ui.write = oldwrite
+        commitmessages = parsemessage(ui, editedmessages, appliedbefore)
+        if commitmessages:
+            savecommitcomments(ui, repo, mq, appliedbefore, commitmessages)
+            ui.write = oldwrite
+        else:
+            ui.write = oldwrite
+            return None
 
 def fullstatus(repo, node1):
     """Gets status between ode1 and its first parent."""
        "HG: Applied patches:\n"
        "HG: --\n")
 
-def parsemessage(text):
+def parsemessage(ui, text, appliedbefore):
     """Parses the edited text.
 
     It parses it to a map from patch name to lines of the commit messages
                 if not currentpatch in commitcomments:
                     commitcomments[currentpatch] = []
                 commitcomments[currentpatch].append(line)
+
+    
+    appliedbeforenames = []
+    for patch in appliedbefore:
+        appliedbeforenames.append(patch.name)
+    
+    if set(commitcomments.keys()) != set(appliedbeforenames):
+        ui.warn(_("abort: Could not find comments for all patches\n"))
+        return None
+                                                                 
     return commitcomments
 
 def savecommitcomments(ui, repo, mq, appliedbefore, commitmessages):

File tests/test-editcommitmsgs.t

   $ hg log -l1 --template "{desc}\n" -r -3
   This is the first patch
 
+Trying to edit, but removed a comment
+  $ cat > editor3 << '__EOF__'
+  > #!/bin/sh
+  > echo "HG: Enter commit messages for the different patches."  >> $1
+  > echo "HG: Lines beginning with 'HG:' is used to apply the" >> $1
+  > echo "HG: messages to the right patch, and gives some status on the patch" >> $1
+  > echo "HG: Which can help you write the commit messages, so please do not" >> $1
+  > echo "HG: edit them" >> $1
+  > echo "HG: --" >> $1
+  > echo "HG: Applied patches:" >> $1
+  > echo "HG: --" >> $1
+  > echo "HG: Patch: p1" >> $1
+  > echo "This is the first patch" >> $1
+  > echo "HG: --" >> $1
+  > echo "HG: Patch: p2" >> $1
+  > echo "This is the second patch" >> $1
+  > echo "This is second line of second patch" >> $1
+  > echo "HG: --"  >> $1
+  > echo >> $1
+  > __EOF__
+  $ chmod 777 `pwd`/editor3
+  $ HGEDITOR="'`pwd`'"/editor3 
+  $ hg qeditcommitmsgs
+  $ hg log -l1 --template "{desc}\n"
+  This is the third patch
+  $ hg log -l1 --template "{desc}\n" -r -2
+  This is the second patch
+  This is second line of second patch
+  This is the second patch
+  This is second line of second patch
+  $ hg log -l1 --template "{desc}\n" -r -3
+  This is the first patch
+  This is the first patch
+
 Trying to edit commit message, now shows status info
   $ hg qnew p4
   $ hg qeditcommitmsgs --showstatus
+  patch p4 is empty