Is there a way to prepare git tag posts?

When adding a new tag to git, I would like to automatically change the default tag message (empty) before my $ EDITOR lights up - just like git allows you to prepare commit messages via prepare-commit-msg hook.

For instance:

 git tag -s v1.2.3 

should open my editor with pre-populated contents as follows:

 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, hook prepare-commit-msg does not work with tag messages. (Either this, or I was too dumb to learn how to do this.)

+5
source share
2 answers

You can create an alias that first populates the temporary file with the desired content, and then runs the git tag with the -F <file> / --file=<file> option to pass the contents of the temp file to the tag message. Theoretically, something like this:

 [alias] tag-prepare = !~/bin/prepare_file.sh && git tag --file="/home/user/temp/temp.txt" 

Then you invoke it with git tag-prepare v1.2.3 .

Please note that the prepare_file.sh script needs to create the entire tag message, because the --file parameter does not open the editor to edit the content anymore, it only accepts w / e in the provided file and uses it as a message.

+4
source

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 creating the tag and open the editor. In my case vim : enter image description here

0
source

Source: https://habr.com/ru/post/1498131/


All Articles