当我运行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 <[email protected]>
HG: branch 'default'
HG: added a.txt
有没有办法自定义这个文件?我想包括工作副本是否有任何未知文件。
没有正式的方法可以做到没有修改mercurial本身(不是非常令人生畏,它是非常干净的Python),但是通过调整editor
来设置[ui]
的~/.hgrc
部分,这是一种方法:
editor = hg status --unknown >! /tmp/unknown_list ; /usr/bin/vim -c "r /tmp/unknown_list"
也就是说,当然是特定于Linux的vim,但对于任何操作系统上的任何体面编辑器都可以这样做。
我想在windows下这样做。在ini / .hgrc文件中自定义编辑器设置的想法让我想到用命令文件替换编辑器命令。
例如如果你在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
(当然,您不必使用记事本。)
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
可以在'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)
使用hg commit -m "My message here"
。您还可以在Mercurial.ini
或~/.hgrc
文件中设置编辑器。添加以下内容:
[ui]
editor = /path/to/your/favorite/editor
有很多方法可以做到这一点。有些甚至是listed on the official wiki。这扩展了@ Ry4an的答案。你可以将它添加到你的~/.hgrc
[ui]
editor = function hgvi { hg status --unknown | sed 's/^/HG: /g' >> "$1"; vi "$1"; }; hgvi