Diff at end of commit message

Yuya Nishihara yuya at tcha.org
Tue Feb 20 13:25:21 UTC 2018


On Sat, 17 Feb 2018 18:42:59 +0100, Stefan Schwarzer wrote:
> When I commit a change, I edit the commit message in the
> editor. Inside the editor, I like a diff of the changes
> that are about to be committed.
> 
> I found out that I can set a template for the commit
> message in my Mercurial configuration file under
> `[committemplate]`. At the moment, I use
> 
> [committemplate]
> changeset = {desc}\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")}
>    HG: ------------------------ >8 ------------------------
>    HG: Do not touch the line above.
>    HG: Everything below will be removed.
>    {diff()}
> 
> which I took from the `hgrc` manpage and added the `{diff()}`
> at the end.
> 
> I have two questions:
> 
> - What I'd ideally like would be the "default commit template"
>   for the version of Mercurial plus the `diff` call. This means
>   if I update to a new Mercurial version, the then-current
>   default commit template (possibly depending on special
>   situations like merges) should be used, plus the diff. Is
>   there a way to achieve this?

Appears that there's no one-off flag to include the default commit text.

> - I noticed that the above template also includes binary diffs.
>   Usually these aren't useful. Is there a way to let `{diff()}`
>   or a similar placeholder only contain text changes?

diff("set:not binary()") can be used to exclude binary files. See
"hg help fileset" for details.



More information about the Mercurial mailing list