Clearcase : list of files removed in latest label - clearcase

In Clearcase, I need to find difference between two labels which include new added files, modified files and removed files in new label.
I have used the below script, but it is not giving me correct data:
#!/bin/sh
REL_LBL_1=REL1_7
REL_LBL_2=REL1_8
echo "\n ${REL_LBL_2} versions of files that replaced ${REL_LBL_1}
versions ..."
echo "====================================================="
cleartool find -avobs -element "{lbtype_sub(${REL_LBL_2}) &&
lbtype_sub(${REL_LBL_1})}" -version "{lbtype(${REL_LBL_2}) && !
lbtype(${REL_LBL_1})}" -print
echo "\n Files created new to ${REL_LBL_2} ..."
echo "====================================================="
cleartool find -avobs -element "{lbtype_sub(${REL_LBL_2}) && !
lbtype_sub(${REL_LBL_1})}" -version "lbtype(${REL_LBL_2})" -print
echo "\n ${REL_LBL_1} files removed in ${REL_LBL_2} ..."
echo "====================================================="
cleartool find -avobs -element "{lbtype_sub(${REL_LBL_1}) &&
lbtype_sub(${REL_LBL_2})}" -version "lbtype(${REL_LBL_1})" -print

cleartool find -avobs -element "{lbtype_sub(${REL_LBL_1}) &&
lbtype_sub(${REL_LBL_2})}" -version "lbtype(${REL_LBL_1})" -print
output of this is displaying some files, but when I checked in the latest label, those files still exist
That could because those same files were added to source control again at some point after having being deleted.
Check their version history.
cleartool find -avobs -element "{lbtype_sub(${REL_LBL_1}) &&
lbtype_sub(${REL_LBL_2})}" -version "lbtype(${REL_LBL_1})" -print
Or that could be because that query does not list "files removed in ${REL_LBL_2}". It would still display any element with ${REL_LBL_2} as well as ${REL_LBL_1}
Try at least:
cleartool find -avobs -element "{lbtype_sub(${REL_LBL_1}) &&
lbtype_sub(${REL_LBL_2})}" -version "lbtype(${REL_LBL_1}) && !lbtype(${REL_LBL_2})" -print
purpose of this script is, i'm planning to migrate Clearcase to GIT, below is the plan -
I will put data from cleacase label-1 in GIT and apply tag label-1 in GIT.
I will findout diff between label-1 and label-2 in Clearcase and copy the diff in GIT and apply tag label-2 in GIT.
For the 2nd point, I will using the above script to identify, modified files, removed files and new files
The thing is... you don't need to script. At all.
Simply set your ClearCase view to label 2, and add that content to your git repo:
cd /path/to/git/repo
git --work-tree /path/to/clearcase/view/set/to/label_2 add .
git commit -m "Import label 2"
git tag -m "label2 import" label2
Git will detect automatically what has been added/modified and deleted!

Related

Is it possible to remove the label from entire version tree?

From every branch and node.
Not only in branch of current view.
I have tried using "cleartool rmlabel -rec YOUR_LABEL yourDirectory" . but it removes only current view of version.
You can try instead to remove the entire label type:
cleartool rmtype -rmall yourlabel#\avob
But be careful, that would remove all instances of that label anywhere in that repo.
See another example of rmtype with "How to delete a clearcase branch with a single command?" using find and cleartool rmlabel.
Since you don't want to remove the label in the all vob, only in a given folder, you need to apply a slower solution, searching files with that label in your folder and subfolders:
cd /path/to/your/folder
cleartool find . -version "{lbtype(LABEL)}" -print
If the above line do print version for files in your folder and your subfolder, then try:
cd /path/to/your/folder
cleartool find . -version "{lbtype(LABEL)}" -exec "cleartool rmlabel YOUR_LABEL \"%CLEARCASE_XPN%\""

How to find list of all files modified by user in all clearcase branches?

I am new to cleartool.
I did some changes in .cs files from main latest.
I have to copy those changes in particular branch.
I have tried this command
cleartool find . -all -nvisible -name "*" -version "{created_by(mayur_shingote) && created_since(01-Sep-2017)}" -print

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

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") ?
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.
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".

get elements of a label with version before LATEST

This command gets elements of a label with latest version:
cleartool find . -element "{lbtype_sub(LABEL1) && version(/main/LATEST)}" -print
how do I get elements of a label with version before LATEST?
If you mean, how to get any version with the right label, but which aren't LATEST, you could do it in two passes:
cleartool find . -version "{lbtype_sub(LABEL1)}" -print > labelled_versions.txt
That would find all versions with the right label.
Remember a label can be applied to only one version per element.
You can restrict it per branch if you want:
cleartool find . -version "{lbtype_sub(LABEL1) && brtype(myBranch)}" -print > labelled_versions.txt
# for instance, for main:
cleartool find . -version "{lbtype_sub(LABEL1) && brtype(main)}" -print > labelled_versions.txt
(That would exclude versions labelled, but part of a different branch than main)
Then you can use a dynamic view, and for each version found, check if that version is the same as the one selected in your dynamic view (using fmt_ccase):
cleartool descr -fmt "%n" M:\MyView\myVob\path\to\myFile

Cleartool - find unloaded/removed files

Is there a command in Cleartool which i can use to list all files which have been removed from a branch?
Thanks
The basic command to find anything in ClearCase is... cleartool find, also illustrated in "ClearCase UCM: Need to See Content of Deleted File".
In your case, you would search for versions of files which aren't at the LATEST of a branch:
cleartool find . -type f -version "! version(.../BRANCH/LATEST)" -print
(see version selector for more on this '.../' notation)
To display only the file (and not all the versions):
cleartool find . -type f -element "! version(.../BRANCH/LATEST)" -print
The OP linuxlewis mentions in the comments:
this will show all differences which exist between sibling branches. I just want to be able see the file names,if any were removed,from the current branch
I mention the possibility of a grep for BRANCH, to detect files which have versions in BRANCH but not LATEST)
However, a cleaner solution is to add another filter to the search: && version(.../BRANCH)
cleartool find . -type f -element "! version(.../BRANCH/LATEST) && version(.../BRANCH)" -print
That will search all "elements" (files or directories in ClearCase) which have versions in branch BRANCH, but not one in BRANCH/LATEST.

Resources