Reputation: 2100
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.)
Upvotes: 5
Views: 4049
Reputation: 959
You can do something like this
message="A header line
A body line...
Other lines...
Final line...
"
git tag --annotate --message "${message}" --edit 0.8.0
It will start tag creation and opens an editor. In my case vim
:
Upvotes: 3
Reputation: 6223
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.
Upvotes: 4