Push from Mercurial to ClearCase

# 20 Jun 2010

I sometimes like do my development work in a local Mercurial repo even though I’m stuck checking into ClearCase in the end.

I create a fresh snapshot view in ClearCase, create a Mercurial repo on the view, then do my work in a clone of that Mercurial repo. It isn’t ideal, but it allows me to delay all the file checkin/checkout work required when dealing with ClearCase. The main advantage is that it frees me to use whatever IDE or text editor I want, without relying on an integrated ClearCase plugin.

The tricky part comes when it is time to push my changes from my clone to the hybrid Mercurial/ClearCase repository/snapshot view — or more accurately, after the push, during a hg update on the hybrid repo/view.

I’ve been using this bash script (run in Cygwin since ClearCase isn’t available for OS X) to help with that step.

#!/bin/env bash

while [ 1 ]; do
  file=`hg up 2>&1 1>/dev/null | grep abort | grep "Access is denied" | awk -F" " ''{print $2}'' | awk -F":" ''{print $1":"$2}''`
  if [ "$file" == "" ]; then
    echo "No pending updates."
    exit 1
  echo "$file"
  cleartool co -nc $file

It continuously attempts to update (via hg update) the hybrid repo/view, and looks for files that need to be Checked Out in the ClearCase snapshot, and then checks them out.