Command to delete branches of Clearcase element with "0" versions

12,392

Solution 1

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.

Solution 2

rmver won't work.

/home/ccadmin $ cleartool rmver -force ./VaREngine/Makefile@@/main/nz_mig/nz_relOne/0 cleartool: Error: Cannot delete version zero without deleting branch: "./VaREngine/Makefile".

Share:
12,392
Bhaskar
Author by

Bhaskar

Updated on June 04, 2022

Comments

  • Bhaskar
    Bhaskar almost 2 years

    What is the command in Clearcase to delete the branches of an element in which it is not modified (Element's version in that branch is "0") ?

  • Bhaskar
    Bhaskar over 10 years
    The command is applicable to a single file. But, say if I have a list of 100 files in a directory, then how to go about it ?
  • Tamir Gefen
    Tamir Gefen over 10 years
    @VonC, you may mention that there's also a trigger he can use to automatically remove those versions (he can apply it for the next times)
  • VonC
    VonC over 10 years
    @Bhaskar I have edited the answer to address your point (100 files to clean up).
  • VonC
    VonC over 10 years
    @TamirGefen good point. I have edited the answer to include a reference to that trigger.
  • VonC
    VonC over 10 years
    The try out the second option of my answer above: cleartool rmbranch -f.
  • Andrew T Finnell
    Andrew T Finnell almost 6 years
    Doesn't the find avobs command find any version which is NOT version 1? Thus if there is a version 2, it is listed. I just tried it out and that is what i found.
  • VonC
    VonC almost 6 years
    @AndrewTFinnell 5 years later... that is possible (I don't have access to ClearCase anymore). Did you manage to find a query which does exclude any branch with a version 1?
  • Andrew T Finnell
    Andrew T Finnell almost 6 years
    @VonC Are you trying to find any branch which ONLY has a Version 1? Or exclude any branch which happens to have a version >= 1? It's been a bit of time and I missed your question. Feel free to start a chat or ask a Question on here and link it to me. I'll be glad to answer here, in the question or chat. I just had to do this a month ago and moved from CC to Git.
  • VonC
    VonC almost 6 years
    @AndrewTFinnell No, the goal is to edit the answer above in order to address those different use case you mentioned in your comments. Feel free to add those in the answer.
  • Andrew T Finnell
    Andrew T Finnell almost 6 years
    @VonC No worries. I'm hoping you can clarify your question though. I asked an either or question so I know which way to answer it. Perhaps I was unclear my apologies for mixing two discussions. Do you wish to exclude elements which ONLY have a Version 1 on a branch, or exclude elements which have version >= 1? Which would mean you want to find version=0.
  • VonC
    VonC almost 6 years
    @AndrewTFinnell myquestion stemmed from your question ;) Your question was that my answer would find "any version which is NOT version 1", which means it would not be a good answer to the OP. The goal was to find any branch with only a version 0. In order to then delete them.