How can I uncheckout a file in all of my temporary views in command line? - clearcase

Background
I currently am testing a script that creates a temporary view and checks out four package files to be updated by a process. However, my script hasn't gotten to the point where it can reach the uncheckout step. This results in 30+ temporary views that all contain a checkedout version of the package files.
Attempted solution
I could go in to the graphical clearcase tree and manually ctrl-click all the temp views that are checked out, then click on the uncheckout button. However, this will get unweildy after a few hundred tests, so I want to know of a command line way to do this. All of my temporary views are formatted with "TMP_abc_QUA_###".
Question
How can I uncheckout a file across all temporary views from linux command line with bash?

As described in "How to remove checked-out references of a view from a VOB", you can simply describe a vob:
cleartool describe -long vob:\baseccvob
You will see which views are holding objects:
VOB holds objects from the following views:
MYHOST:C:\VIEW\TEST.vws [uuid a7fc590.42f34d53.ae68.b6:30:f5:30:c5:a4]
For each views which are part of your temporary views, you can do:
cd /aview/aVob
cleartool rmview -uuid fa7fc590.42f34d53.ae68.b6:30:f5:30:c5:a4
That will remove any checkout status for any file in aVob for that view.
Loop and repeat for other temp views.
I used in the past (Windows syntax)
cd M:\aview\avob
ct descr -l vob:\aVob|grep TMP_|gawk "{gsub(/]/,\"\",$3); print \"cleartool rmview -uuid \"$3}"|cmd
On Linux:
cd /views/aView/vobs/aVob
cleartool descr -l vob:/vobs/aVob|grep TMP_|gawk "{gsub(/]/,\"\",$3); print \"cleartool rmview -uuid \"$3}"|sh

Related

ClearCase UCM: Access and change config spec from script

In our continuous integration we use ClearCase UCM. We occasionally need to access the sources from the recommended baseline (which not necessarily equals the newest baseline). Note: All baselines are full.
I figured out how to access the sources belonging to the recommend baseline manually, by entering cleartool edcs in the command line within the dynamic view and adding the line element * MyRecommendedBaseline below # Select checked out versions, saving and closing the text-file.
Unfortunately I don't know how to do this from a script. One way I could think about is read the contents of the config_spec into a stream, add the line, save it to a new text file and use "cleartool setcs newcs.txt".
But apart from being cumbersome I'm not exactly sure if this is possible. Anyone knows a simple way to do this?
You can script listing the recommended baselines of a given stream: see "How can I list the recommended base line in ClearCase"
On Windows:
cleartool descr -fmt "%[rec_bls]CXp" stream:streamName#\aPVob
On Unix:
cleartool descr -fmt "%[rec_bls]CXp" stream:streamName#/vobs/aPVob
From there, you can generate a new file with simple rules:
element * MyRecommendedBaseline1
element * MyRecommendedBaseline2
...
And you can setcs that file to a dedicate base-CC dynamic view (not an existing UCM view).
As Brian Cowan points out in the comments, this only works because those baselines, as the OP mentions, are full baselines (not incremental or not-labeled, like deliverbl are).
See also "What is the difference between Full baseline and Incremental baseline in Clearcase UCM?".

How to delete a view tag with special characters in ClearCase

I have a view, for some reason, it was named with a special character: "0x7f", at least I think so..
For example:
MyView123456 -> MyView'0x7f'123456
I can only found this view by
ct lsview #list all views.
And I found this "0x7f" when dump the outputs to a file.
And using vim.
Now I'm trying to delete this view totally.
I can unregistered and delete the view itself by -uuid.
But I cannot delete the view tag.
And I also found wildcard '*' seems not working.
Does anyone know how to delete this view tag?
P.s. I'm under Linux, and no GUI.
Try first if dome of the workaround described in "Removing ClearCase objects whose name begins with a hyphen", when using cleartool rmtag:
cleartool rmtag -- MyView*
Note the use of '--' in order to separate the command from its parameters
The wildcard being expanded by your shell, try and use it instead in the cleartool interractive session:
cleartool
> rmtag -- MyView*
In Linux shell, see if a single quote is enough:
cleartool rmtag -- MyView'0x7f'123456
# or
cleartool rmtag -- 'MyView0x7f123456'
I was able to create and remove a view with binary data in the tag using Perl. You have to use the OCTAL value of 177 in the strings.
I created my view using this command line:
perl -e '`cleartool mkview -tag myview\177tag /net/bullwinkle/export/vobstg/binarytag.vws`'
And I successfully removed that view tag using this command line:
perl -e '`cleartool rmview -tag myview\177tag`'
If the view was unique enough, you could also use (on Unix) or at least try:
cleartool rmview -tag `cleartool lsview 'myview*123456'`
There is another mechanism, if all else fails: you can edit the vob_tag registry file. This would require an outage as the registry file is loaded into the registry server's memory on clearcase startup and only re/written after that point.
The process is:
Stop ClearCase on the registry server
CD to /var/adm/rational/clearcase/rgy (Unix) or {CC Install dir}\var\rgy (Windows)
Back up the vob_tag file.
load the vob_tag file in an editor. (vi/gedit on unix, but I'd use notepad++ on windows)
locate the problem view tag (you may need to search on the global path or some other component of the name).
Make note of the path to the view.
Delete the line.
Start ClearCase on the registry server
unregister the view or retag it with an easier-to-access tag.

How do I label new files on a branch using cleartool?

To provide some context, I am trying to write a script which will take a text file with clearcase elements in it, and label all of those elements.
To generate the text file, I am basically using the following command:
cleartool find -a -nxn -ele "brtype(branchName)" -print > "textfile.txt"
Then I go through the text file and remove the elements I don't want to label. The last step would be to feed the text file into a script which would repeatedly call a cleartool command on each line of the file.
For all existing files/folders, I can run this command:
cleartool mklabel -rep "label_name" (element_path)
Where I run into trouble is with files that have been added to the branch. They print out to the text file in a format that isn't recognized by the "mklabel" command and I can't find a good way to parse them.
The format of the files is similar to the following:
\original_folder_path##\branch_name\version_number\new_sub_folder_path\branch_name\version_number\file_name.java
In the past I have used this generic command we use at my company to blindly label all files in a branch:
cleartool find -all -branch "brtype(<branch>)" -version "version(.../<branch>/LATEST) && !version(.../<branch>/0)" -visible -exec "cleartool mklabel -rep <label_name> %CLEARCASE_XPN%"
But I only want to label about half the files on the branch I am using, and there are too many to label them individually. I am sure I am missing something obvious here. Does anyone know how I should change my find or mklabel command to accommodate the new files and folders?
That format "\original_folder_path##\branch_name\version_number" is an extended pathname, and isn't reserved for "added file".
It is current rather for files listed by a cleartool find, but not visible (directly accessible) in the view used by the cleartool find.
You need to make sure to use a view which is set to select the LATEST from brname.
If you see extended pathnames in your cleartool find, you can ignore them: they are not accessible by said view.
Or you could use a cleartool find -cview, in order to limit the results to what you view is able to select and see.

Delete file from ClearCase checked out on another branch

I am trying to delete a file in ClearCase. When I attempt to delete it I get a message that the element has checkouts. When I do a version tree on the file I see that the file is checked out by another user, in another view, on a different branch.
How do I delete this file? In addition why doesn't ClearCase let me delete this file?
You can delete it through the command line and cleartool, by forcing its delete (option which isn't available with the GUI)
cleartool rmname -force theFile
Don't forget to checkout the parent directory first, then to checkin that same parent directory, in order for everyone to see that you have dereferenced that file within said directory.
See cleartool rmname:
–f/orce:
Forces the removal of the name when there is at least one checkout of the element.
When used with –nco, suppresses the prompt for confirmation.
That will work even when you had this before:
, as explained in the technote "About cleartool rmname and checkouts".

ClearCase - file system path to element path

Given a file system path such as "D:\pkirkham_view\VOB\Folder" or "U:\VOB\Folder\", is there a mechanism to get the path which would work in the config-spec to to load that folder "/VOB/Folder/" ?
Either CAL or cleartool commands would be fine. This is to run on client machines with ClearCase LT installed.
(I haven't found anything usable in CCElement.get_PathInView() or the various cleartool ls commands I've tried)
There is no native command, but the only load rule you need is based on a vob name.
So you need a script able to:
1/ remove everything including the name of the view
(which you can obtain with a '<aPathTo>\VOB\Folder\;cleartool cleartool lsview -s -cview)
D:\pkirkham_view\VOB\Folder => \VOB\Folder
U:\VOB\Folder\ => \VOB\Folder
2/ Build your load rule accordingly:
load \VOB\Folder
3/ Append that load rule to your config spec (if you are already within the view):
cleartool catcs > aConfisgpec.txt
echo "load \VOB\Folder" >> aConfisgpec.txt
cleartool setcs aConfisgpec.txt
The OP comments:
So, if I create a snapshot view whose tag name is 'pkirkham_testing_view' on path 'D:\thursday', how is that a substring extract?
That is a good point, since one can name the root directory with any name.
I would recommend naming that directory with the tag of the view.
But that is not the case, you need to determine the root directory of a snapshot view:
start in 'D:\whatever\path\VOB\Folder',
try a cleartool lsview -cview:
if it respond correctly, cd .., and repeat 2.
When it exit with an error, remove the substring of that directory from the initial path. What remains will be your load rule.

Resources