如何自定义“提交消息文件”由“hg commit”生成?

发布于 2024-10-04 21:36:31 字数 460 浏览 4 评论 0原文

当我运行 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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

心欲静而疯不止 2024-10-11 21:36:32

有很多方法可以做到这一点。有些甚至在官方 wiki 上列出。这扩展了@Ry4an 的答案。您可以将其添加到您的 ~/.hgrc

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

There are many ways to do this. Some are even listed on the official wiki. This expands on @Ry4an answer. You can add this to your ~/.hgrc

[ui]
editor = function hgvi { hg status --unknown | sed 's/^/HG: /g' >> "$1"; vi "$1"; }; hgvi
时光暖心i 2024-10-11 21:36:31

可以在 [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)

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)
吐个泡泡 2024-10-11 21:36:31

没有官方的方法可以在不修改 Mercurial 本身的情况下做到这一点(不是非常吓人,它是非常干净的 Python),但这里有一种方法可以通过调整 editor 设置 [ui] 来做到这一点~/.hgrc 部分:

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

也就是说,当然是 Linux 上的 vim,但对于任何操作系统上的任何像样的编辑器都可以做同样的事情。

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.

笛声青案梦长安 2024-10-11 21:36:31

我想在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

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

I wanted to do this under windows. The idea of customising the editor setting in the ini/.hgrc file made me think of replacing the editor command with a command file.

e.g. if you set this in mercurial.ini:

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

then hg will call the command file and pass the name of the temp file on the command line. The temp file name can then be accessed in the command file using the %1 parameter.

hgedit.cmd could be something like:

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

If you want to append the output of hg as comments you could do this:

@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

(You don't have to use notepad of course.)

谈场末日恋爱 2024-10-11 21:36:31

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

A Mac/Linux variant of Jim Eggleston's answer... I made a script called hg-commit-editor:

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

and then set it as my commit editor in my hgrc:

[ui]
editor = hg-commit-editor
溺孤伤于心 2024-10-11 21:36:31

使用hg commit -m“我的消息在这里”。您还可以在 Mercurial.ini~/.hgrc 文件中设置编辑器。添加以下内容:

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

Use hg commit -m "My message here". You can also set up an editor in your Mercurial.ini or ~/.hgrc file. Add the following:

[ui]
editor = /path/to/your/favorite/editor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文