如何自定义`hg commit`生成的'commit message file'?

时间:2010-11-27 13:18:11

标签: mercurial

当我运行hg commit时,Mercurial会为我的提交消息生成一个如下所示的文件:

HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: Henri Wiechers <hwiechers@gmail.com>
HG: branch 'default'
HG: added a.txt

有没有办法自定义此文件?如果工作副本有,我想包括 任何未知的文件。

6 个答案:

答案 0 :(得分:3)

没有正式的方法来修改mercurial本身(不是非常令人生畏,它是非常干净的Python),但这是通过调整editor设置[ui]部分来实现的方法您的~/.hgrc

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

那当然是特定于Linux的vim,但对于任何操作系统上的任何体面编辑器都可以这样做。

答案 1 :(得分:2)

我想在Windows下执行此操作。在ini / .hgrc文件中自定义编辑器设置的想法让我想到用命令文件替换编辑器命令。

e.g。如果你在mercurial.ini中设置它:

[ui]
editor = c:\path\to\hgedit.cmd

然后hg将调用命令文件并在命令行上传递临时文件的名称。然后可以使用%1参数在命令文件中访问临时文件名。

hgedit.cmd可能类似于:

@echo off
hg status --unknown>>%1
notepad %1

如果你想将hg的输出作为注释附加,你可以这样做:

@echo off
echo HG: -->>%1
echo HG: Unknown files:>>%1
for /f "tokens=*" %%a in ('hg st --unknown') do echo HG: %%a>>%1
notepad %1

(当然,你不必使用记事本。)

答案 2 :(得分:2)

Jim Eggleston答案的Mac / Linux变体......我制作了一个名为hg-commit-editor的脚本:

#!/bin/sh
hg status --unknown | sed -e 's|^|HG: |' >> $1
editor $1

然后将其设置为我的hgrc中的提交编辑器:

[ui]
editor = hg-commit-editor

答案 3 :(得分:1)

使用hg commit -m "My message here"。您还可以在Mercurial.ini~/.hgrc文件中设置编辑器。添加以下内容:

[ui]
editor = /path/to/your/favorite/editor

答案 4 :(得分:0)

有很多方法可以做到这一点。有些甚至是listed on the official wiki。这扩展了@ Ry4an的答案。您可以将其添加到~/.hgrc

[ui]
editor = function hgvi { hg status --unknown | sed 's/^/HG: /g' >> "$1"; vi "$1"; }; hgvi

答案 5 :(得分:0)

可以在“ committemplate”配置部分进行指定(请参阅“ 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)
相关问题