Re: Proposal: Allow Customization of Git Merge Commit Message Template

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-12-05 at 17:00:56, dangling . wrote:
> Proposal:
> Introduce an option (e.g., a configuration setting or CLI flag) that allows users to specify a custom merge commit message template. For example:
> 
> - A new configuration option:
>   ```sh
>   [merge]
>       messageTemplate = "Merge %s into %s"
>   ```
>   Here, `%s` placeholders could represent the source and destination branches, respectively.

I think in general that such an option would need multiple placeholders.
Just because in English we place the name of the second head before the
name of the first head does not mean that that is true in all languages
or translations.

> - Alternatively, a command-line flag:
>   ```sh
>   git merge --message-template="Merge %s into %s" upstream/main
>   ```

I think this can be done more generally with a `prepare-commit-msg`
hook:

----
#!/bin/sh

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2

case "$COMMIT_SOURCE" in
 merge)
   /usr/bin/perl -i.bak -pe '
   s/Merge remote-tracking branch '\''(.*)'\''/Merge $1/
   ' "$COMMIT_MSG_FILE"
   ;;
 *) ;;
esac
----

That's the approach we would generally recommend here, since it's more
flexible and allows you more customization over the message.  Of course,
you can use sed or Ruby instead (or even ed or ex) if you prefer.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux