When adding a new tag in git, I would like to automatically modify the default (empty) tag message before my $EDITOR fires up—similar to the way that git allows to prepare commit messages via the prepare-commit-msg
hook.
For example:
git tag -s v1.2.3
should open my editor with pre-filled contents like this:
Release v1.2.3:
* Dynamically generated message 1
* Dynamically generated message 2
Default standard text.
#
# Write a tag message
# Lines starting with '#' will be ignored
Is there any way to achieve this? Unfortunately, the prepare-commit-msg
hook doesn’t work with tag messages. (Either this, or I was too dumb to find out how to do it.)
You could create an alias which would first populate a temp file with the desired content and then run git tag
with the option -F <file>
/--file=<file>
to feed the temp file's content into the tag message. Theoretically, something like this:
[alias]
tag-prepare = !~/bin/prepare_file.sh && git tag --file="/home/user/temp/temp.txt"
You would then call it with git tag-prepare v1.2.3
.
Note that the prepare_file.sh
script needs to create the entire tag message because the --file
option does not open the editor to edit the content anymore, it only takes w/e is in the provided file and uses that as the message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With