twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

prefix commitMessageTemplate with custom template #3328

Closed lgersman closed 10 months ago

lgersman commented 10 months ago

Is your feature request related to a problem? Please describe.

I can customize the commit message using

[git]
    commitMessageTemplate = "my commit message"

but in this case i am missing the changes made by the commit

Example:

commit 81b32f057caf3d02013d39e6f1dd54fb6e9bc2ed
Author: xxx <xxx@gmail.com>
Date:   Sun Nov 5 20:05:23 2023 +0100

    Add bin/ocr-tesseract-img.sh

I would like to define a commit message template containg a custom template string BUT would also like to have the changes (the default chezmoi commitMessageTemplate) noted in the message.

Just like this:

Example:

commit 81b32f057caf3d02013d39e6f1dd54fb6e9bc2ed
Author: xxx <xxx@gmail.com>
Date:   Sun Nov 5 20:05:23 2023 +0100

    my commit message

    Add bin/ocr-tesseract-img.sh

I am aware of the fact that I can even use chezmoi git -- log --stat to see both commit message and changed files using git (BTW: Why does chezmoi git log --stat not work ?`).

Describe the solution you'd like

Provide a template variable containing the default commit message generated by chezmoi

Thank's for creating such a great software !

halostatue commented 10 months ago

You can do this with a more extensive commitMessageTemplate string or the new (as yet unreleased) commitMessageTemplateFile specification. You would need to add your custom message at the top and copy the default commit message template into your template.

@twpayne I wonder if it might be possible to have something like {{ includeTemplate "chezmoi:COMMIT_MESSAGE.tmpl" }} work?

twpayne commented 10 months ago

You can do this with a more extensive commitMessageTemplate string or the new (as yet unreleased) commitMessageTemplateFile specification. You would need to add your custom message at the top and copy the default commit message template into your template.

Exactly. Please wait for commitMessageTemplateFile and copy the default commit message template.

@twpayne I wonder if it might be possible to have something like {{ includeTemplate "chezmoi:COMMIT_MESSAGE.tmpl" }} work?

I think that something like this makes sense when chezmoi has multiple built-in templates. Right now, this is not the case and copying the standard template instead makes sense.

halostatue commented 10 months ago

@twpayne I wonder if it might be possible to have something like {{ includeTemplate "chezmoi:COMMIT_MESSAGE.tmpl" }} work?

I think that something like this makes sense when chezmoi has multiple built-in templates. Right now, this is not the case and copying the standard template instead makes sense.

Not that the COMMIT_MESSAGE.tmpl file has changed recently, but includeTemplate "chezmoi:COMMIT_MESSAGE.tmpl" support would make it so that if it were updated, people would get the benefit on upgrade without having to learn that COMMIT_MESSAGE.tmpl has been updated upstream.

twpayne commented 10 months ago

There's an added complication that with #3322 the structure of the data passed to COMMIT_MESSAGE.tmpl changed from passing just the git status as . to passing a full set of chezmoi template variables in .chezmoi with the status in .chezmoi.status and a bunch of field renames for consistency. Effectively, #3322 makes the data passed to COMMIT_MESSAGE.tmpl part of chezmoi's API (relevant XKCD.

twpayne commented 10 months ago

Fixed by #3322. Please re-open if you have further questions.