#! /bin/bash -eu # This is a Mercurial hook script which sits in your team's master repository, and tags every time someone pushes a new head. # The idea is that you can distinguish changesets which were just local working commits from ones which were released to the team. # Note that if you want to know who did a push, it's the user in whose name the tag was made # [hooks] # changegroup.tag = /path/to/tag-changegroup.sh name-for-this-repo # don't keep the script as a versioned file in the repository, as it will all go horribly wrong when it updates around branches # when a hook runs, pwd is the root of the repo; you could consider storing the tag script inside the .hg directory REPO_NAME=$1 # TODO: support different strategies for update before tagging: # 1. don't; put the tag wherever # 2. update to the changeset being tagged, as now # 3. switch to a configured branch or bookmark, so that tags are always in some out-of-the-way place where users don't need to pull immediately HG_REV=$(hg identify -r $HG_NODE -n) hg heads --template '{rev} {node} {branch}\n' | while read HEAD_REV HEAD_NODE HEAD_BRANCH do if [[ $HEAD_REV -ge $HG_REV ]] then # question: does the tag use the HG_NODE or HEAD_NODE? is it based on the identity of the changegroup or the changeset? TAG=$REPO_NAME.$HEAD_BRANCH.$HG_REV echo "Tagging revision $HEAD_REV:$HEAD_NODE as $TAG" hg update -cq -r $HEAD_REV hg tag -q -r $HEAD_REV $TAG fi done echo "DON'T FORGET TO PULL AND MERGE!"