Skip to content

Instantly share code, notes, and snippets.

@fernferret
Created July 25, 2012 19:25
Show Gist options
  • Save fernferret/3178035 to your computer and use it in GitHub Desktop.
Save fernferret/3178035 to your computer and use it in GitHub Desktop.
Finds all Mercurial Branches that have Multiple Heads in a given repo.
#!/bin/bash
# This simple script will look at all named branches in a given repository
# and print out any branch that contains multiple open heads. This is useful
# to see if your repository is clean or if someone has pushed multiple
# anonymous branches.
foundone=""
# Retrieve the branch list. The format will contain other garbage, so only
# grab the name of the branch using gawk. You could use awk if required.
#branchlist=`hg branches | awk '{print $1}'`
branchlist=`hg branches | gawk '{print $1}'`
# Iterate through the branches and find the one(s) that contain multiple heads.
for branch in ${branchlist[@]}
do
count=`hg log -r "head() and not closed() and branch('$branch')" --template "{node}\n" | wc -l`
if [ "$count" != "1" ] ; then
echo -e "\n ====[ $branch ]====\n"
hg log -r "head() and not closed() and branch('$branch')"
echo -e "========================================\n"
foundone="yes"
fi
done
# If no branches contained multiple heads, state that life is good!
if [ -z "$foundone" ] ; then
echo -e "---[ No named branches contained multiple heads. Yay! ]---"
fi
@agushuley
Copy link

Line #19 should contain numeric comparation

  if [ "$count" -ne "1" ] ; then

@dhs-rec
Copy link

dhs-rec commented Mar 1, 2022

Use [[ and it doesn't matter ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment