Erik Zielke avatar Erik Zielke committed 9ca609b

Added test-cases and fixed errors found in the process

Comments (0)

Files changed (4)

 syntax: glob
 *.pyo
-*.pyc
+*.pyc
+tests/annotated/*

editcommitmsgs.py

 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
-'''
+"""
 This extension do only have an effect if Mercurial Queues (mq) is enables.
 Then it will allow you to edit commit messages of all patches in a single file.
-'''
+"""
 import os
 
 from mercurial import extensions
 _patchlinestarter = "HG: Patch: "
 
 def editcommitmsgs(ui, repo, **opts):
-    """"Edit commit message of all applied patches"""
-    try:
-        mq = extensions.find('mq')
-    except KeyError:
-        return
+    """Edit commit message of all applied patches"""
+    mq = extensions.find('mq')
     
     if repo[None].dirty():
         ui.warn(_('abort: local changes found, refresh first\n'))
         return
 
     if not repo.mq.applied:
-        ui.warn(_('No patches applied'))
+        ui.warn(_('No patches applied\n'))
         return
 
     allmessages = introductiontext()
         allmessages += "HG: --\n"
 
     editedmessages = ui.edit(allmessages, ui.username)
-    commitmessages = parsemessage(editedmessages)
-    savecommitcomments(ui, repo, mq, appliedbefore, commitmessages)
+    if editedmessages != allmessages:
+        commitmessages = parsemessage(editedmessages)
+        savecommitcomments(ui, repo, mq, appliedbefore, commitmessages)
+
     ui.write = oldwrite
 
 def fullstatus(repo, node1):
 
     fulltext = []
     fulltext.append(_("HG: user: %s") % ctx.user())
-    if ctx.p2():
-        fulltext.append(_("HG: branch merge"))
-    if ctx.branch():
-        fulltext.append(_("HG: branch '%s'") % ctx.branch())
     fulltext.extend([_("HG: added %s") % f for f in added])
     fulltext.extend([_("HG: changed %s") % f for f in modified])
     fulltext.extend([_("HG: removed %s") % f for f in removed])
     try:
         extensions.find('mq')
     except KeyError:
-        ui.warn(_('could not find mq extensions'))
+        ui.warn(_('editcommitmsgs: could not find mq extensions\n'))
         return
 
     ccmdtable = {"qeditcommitmsgs":

tests/sitecustomize.py

+try:
+    import coverage
+    if hasattr(coverage, 'process_startup'):
+        coverage.process_startup()
+except ImportError:
+    pass

tests/test-editcommitmsgs.t

+Setting up configuration without mq
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "editcommitmsgs=$TESTDIR/../editcommitmsgs.py" >> $HGRCPATH
+  $ hg help editcommitmsgs
+  editcommitmsgs: could not find mq extensions
+  editcommitmsgs extension - 
+  
+  This extension do only have an effect if Mercurial Queues (mq) is enables.
+  Then it will allow you to edit commit messages of all patches in a single
+  file.
+  
+  no commands defined
+
+Setting up configuration with mq
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "mq=" >> $HGRCPATH
+  $ echo "editcommitmsgs=$TESTDIR/../editcommitmsgs.py" >> $HGRCPATH
+  $ hg help editcommitmsgs
+  editcommitmsgs extension - 
+  
+  This extension do only have an effect if Mercurial Queues (mq) is enables.
+  Then it will allow you to edit commit messages of all patches in a single
+  file.
+  
+  list of commands:
+  
+   qeditcommitmsgs   Edit commit message of all applied patches
+  
+  use "hg -v help editcommitmsgs" to show aliases and global options
+
+Creating a repository with some patches
+
+  $ hg init
+  $ touch f1
+  $ hg add f1
+  $ hg qnew p1
+  $ touch f2
+  $ hg add f2
+  $ hg qnew p2
+  $ touch f3
+  $ hg add f3
+  $ hg qnew p3
+  $ echo c3 > f3
+  $ hg status
+  M f3
+
+Trying to edit commit message in unclean repository
+
+  $ hg qeditcommitmsgs
+  abort: local changes found, refresh first
+  $ hg qrefresh
+
+Trying to edit commit messages with no patches applied
+  $ hg qpop -a
+  popping p3
+  popping p2
+  popping p1
+  patch queue now empty
+  $ hg qeditcommitmsgs
+  No patches applied
+  $ hg qpush -a
+  applying p1
+  applying p2
+  applying p3
+  now at: p3
+
+Trying to edit commit message, but doesn't do any changes
+  $ cat > editor << '__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 "HG: --" >> $1
+  > echo "HG: Patch: p2" >> $1
+  > echo "HG: --"  >> $1
+  > echo "HG: Patch: p3" >> $1
+  > echo "HG: --" >? $1
+  > echo >> $1
+  > __EOF__
+  $ chmod 777 `pwd`/editor
+  $ EDITOR="'`pwd`'"/editor
+  $ hg qeditcommitmsgs
+
+Trying to edit commit message, add some changes
+  $ cat > editor2 << '__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 "HG: Patch: p3" >> $1
+  > echo "This is the third patch" >> $1
+  > echo "HG: --" >> $1
+  > echo >> $1
+  > __EOF__
+  $ chmod 777 `pwd`/editor2
+  $ HGEDITOR="'`pwd`'"/editor2 
+  $ 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
+  $ hg log -l1 --template "{desc}\n" -r -3
+  This is the first patch
+
+Trying to edit commit message, now shows status info
+  $ hg qnew p4
+  $ hg qeditcommitmsgs --showstatus
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.