I'd like to set up a git hook that creates a CDN-style directory structure based on incoming tags. So, for example, if the last tag in the local repository is "v1.2.1" and I pull a commit with "v1.2.2", it should see the new tag and clone the repository into a new directly (../1.2.2) accordingly.
I'm pretty sure I want to attach this to post-receive, however I can't find anything in the documentation about git hooks about how to read the incoming tags. Are they delivered on a different hook? Do I actually need to have the shell script run a git command to see if any of the new commits have new tags?
Thanks!
In order to create a Git tag for the last commit of your current checked out branch, use the “git tag” command with the tag name and specify “HEAD” as the commit to create the tag from. Similarly, if you want your tag to be annotated, you can still use the “-a” and “-m” options to annotate your tag.
Tags are ref's that point to specific points in Git history. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1. 0.1). A tag is like a branch that doesn't change.
Tags are refs like any other (like commit).
If tags are pushed to a repo with a post-receive hook, that hook will be called and will list all updated refs, that is both old and new values of all the refs in addition to their names (on its standard input).
See this server post-receive email hook for example.
#!/bin/bash . $(dirname $0)/functions process_ref() { oldrev=$(git rev-parse $1) newrev=$(git rev-parse $2) refname="$3" set_change_type set_rev_types set_describe_tags case "$refname","$rev_type" in refs/tags/*,tag) # annotated tag refname_type="annotated tag" function="atag" short_refname=${refname##refs/tags/} # change recipients if [ -n "$announcerecipients" ]; then recipients="$announcerecipients" fi ;; esac } while read REF; do process_ref $REF; done
For this to work you also must install the functions file from the aforementioned example hook repository.
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