I’m trying to create a hook that blocks pushes to a remote repository if you are trying to push more than once branch.
Here’s the hook:
#!/bin/bash
HG_EXE="/opt/csw/bin/hg"
CHANGESETS=`${HG_EXE} log -r $1:tip --template '{node} '`
i=0
for changeset in ${CHANGESETS}
do
BRANCH=`${HG_EXE} log -r ${changeset} --template '{branches}'`
if [ "${BRANCH}" == "" ]
then
BRANCH="default"
fi
BRANCHES[$i]=${BRANCH}
i=$i+1
done
items=${#BRANCHES[*]}
if [ $items -gt 1 ]
then
i=0
while [ "${BRANCHES[${i}+1]}" != "" ]
do
if [ "${BRANCHES[${i}]}" != "${BRANCHES[${i}+1]}" ]
then
echo "ERROR: You are trying to push more than one branch, use \"hg push -b [branch_name]\""
exit 1
fi
i=$i+1
done
fi
The problem: If I’ve committed on two branches:
changeset: 58:8d2bebe08dd9
user: keshurj <Jay.Keshur@monitisegroup.com>
date: Thu May 26 16:36:49 2011 +0100
summary: commit on default
changeset: 59:43be74e39a44
branch: branch1
tag: tip
user: keshurj <Jay.Keshur@monitisegroup.com>
date: Thu May 26 16:40:25 2011 +0100
summary: commit on branch1
and try to push using hg push –b branch1, the hook still sees ${HG_NODE} as 8d2bebe08dd9, which is on default.
Is there any way to ensure a push is done to only one branch at a time, via a remote hook?
Open to any and all suggestions ( re: this workflow :) )
turns out i was doing something silly....changeset 58 is the parent of changeset 59.
Thanks guys.