Command to delete branches of Clearcase element with “0” versions

You can simply remove the version 0 of that element (that I detail here).

That will remove the associated branch.

cleartool rmver file@@/main/aBranch/0

You would need to “cleartool find” all elements with a version 0 (and no version 1), and rmver those version 0.
For a given branch, this would return all the versions to delete:

cleartool find -type f -version "version(.../blah/LATEST)&&version(.../blah/0)" -print

You can combine that with an exec directive:

# on Windows:
cleartool find ... -exec "cleartool rmver --force \"%CLEARCASE_XPN%\"
# on Unix:
cleartool find ... -exec 'cleartool rmver --force "$CLEARCASE_XPN\"'

Be careful with rmver, this is a destructive operation, so do test that carefully before executing the full find -exec rmver command!


Another approach is mentioned in “Purging Zero-Version-Only Elements in ClearCase” article, by George F. Frazier:

you need to purge your view of those troublesome entities.
Run the following command to find all zero-version elements:

cleartool find -avobs -branch'{
    brtype(mybranch)&&!
    (version(.../mybranch/1))}' 
     -print > c:\files.txt 

This will find all elements with no version 1 on mybranch (if you read closely you’ll notice it doesn’t do the right thing if you have removed the 1 version of an element that already has versions greater than or equal to 2 — this is a rare situation though).
Once finished, it’s simply a matter of using rmbranch to nuke the elements (make sure you know what you’re doing here!).
There are many ways to do that; since I run the MKS toolkit, I execute the following from a command window:

cleartool rmbranch -f 'cat c:\files.txt' 

Tamir suggests a trigger to automatically remove version 0, as listed in the IBM Rational ClearCase: The ten best triggers, under the section Empty Branch.

cleartool mktrtype -c "Automatically remove empty branch" -element -all -postop uncheckout -execwin "ccperl \\mw-ddiebolt\triggers\test_empty_branch.bat" REMOVE_EMPTY_BRANCH

That is good for future cases where an undo checkout leaves a version 0.

Leave a Comment