Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to prepare git tag messages?

Tags:

git

git-tag

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.)

like image 655
igor Avatar asked Oct 03 '22 04:10

igor


1 Answers

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.

like image 159
mart1n Avatar answered Oct 12 '22 12:10

mart1n