Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I customize the 'commit message file' generated by `hg commit`?

Tags:

mercurial

When I run hg commit, Mercurial generates a file for my commit message that looks like this :

HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: Henri Wiechers <[email protected]>
HG: branch 'default'
HG: added a.txt

Is there a way to customize this file? I'd like to include if the working copy has any unknown files.

like image 260
hwiechers Avatar asked Nov 27 '10 13:11

hwiechers


People also ask

How do I edit a commit message in Mercurial?

Fixing the last Mercurial commit You can also use the --amend option to modify the list of files in the commit. Just use hg add and hg rm to modify the index, then make a hg commit --amend to re-commit the changes. When using a Mercurial GUI client, just commit again with selecting the "Amend" option.

How do you undo the last commit in Heartgold?

You can manually trigger a rollback with 'hg rollback'. This will undo the last transactional command. If a pull command brought 10 new changesets into the repository on different branches, then ' hg rollback ' will remove them all. Please note: there is no backup when you rollback a transaction!


2 Answers

It's possible to specify this in the [committemplate] config section (see hg help config.committemplate):

 "committemplate"
----------------

"changeset"
    String: configuration in this section is used as the template to
    customize the text shown in the editor when committing.

In addition to pre-defined template keywords, commit log specific one
below can be used for customization:

"extramsg"
    String: Extra message (typically 'Leave message empty to abort
    commit.'). This may be changed by some commands or extensions.

For example, the template configuration below shows as same text as one
shown by default:

  [committemplate]
  changeset = {desc}\n\n
      HG: Enter commit message.  Lines beginning with 'HG:' are removed.
      HG: {extramsg}
      HG: --
      HG: user: {author}\n{ifeq(p2rev, "-1", "",
     "HG: branch merge\n")
     }HG: branch '{branch}'\n{if(activebookmark,
     "HG: bookmark '{activebookmark}'\n")   }{subrepos %
     "HG: subrepo {subrepo}\n"              }{file_adds %
     "HG: added {file}\n"                   }{file_mods %
     "HG: changed {file}\n"                 }{file_dels %
     "HG: removed {file}\n"                 }{if(files, "",
     "HG: no files changed\n")}

"diff()"
    String: show the diff (see 'hg help templates' for detail)
like image 136
Mathiasdm Avatar answered Oct 20 '22 03:10

Mathiasdm


There's no official way to do it w/o modifying mercurial itself (not terribly intimidating, it's very clean Python), but here's a way to do it by tweaking the editor setting the [ui] section of your ~/.hgrc:

editor = hg status --unknown >! /tmp/unknown_list ; /usr/bin/vim -c "r /tmp/unknown_list"

That is, of course vim on Linux specific, but the same could be done for any decent editor on any OS.

like image 21
Ry4an Brase Avatar answered Oct 20 '22 03:10

Ry4an Brase