Equivalent of mkdir -p for cleartool mkdir - clearcase

UNIX mkdir has the -p flag that creates the parent directories if they don't exist. Is there an equivalent in cleartool for that? Obviously cleartool mkdir foo/bar/ doens't work when foo doesn't already exist.

The simplest way is to create a file in the directory structure and use mkelem -mkpath...
I created a "temp1" directory, and a "temp2" directory, and a "temp.txt" file in one of my sandbox vobs, then added the file to source control with -mkpath from the parent of the "temp1" view private directory.
PS M:\tempview\foobarf\Documents> cleartool mkelem -mkpath .\temp1\temp2\temp.txt
Creating parent directory element ".\temp1\temp2".
Creating parent directory element ".\temp1".
Created directory element ".\temp1".
Checking out parent directory ".\temp1".
Created directory element ".\temp1\temp2".
Checking out parent directory ".\temp1\temp2".
Creation comments for ".\temp1\temp2\temp.txt":
Test1.
.
Created element ".\temp1\temp2\temp.txt" (type "utf16le_file").
Checked out ".\temp1\temp2\temp.txt" from version "\main\0".
It's UTF-16LE because Powershell's Locale is wide character and the "temp.txt" was created using "dir > temp1\temp2\temp.txt".

cleartool mkelem -mkpath is a good option when adding one file.
But if you have multiple files to add, in a tree structure which does not exist yet, don't forget about clearfsimport: it can import flat files to a branch in one command, and will create any missing folder for you.
As seen here: clearfsimport -rec -nset <Source> <target>

Related

clearcase: how to recover a directory

I'm working with clearcase in Unix.
I accidently execute a shell, which make some file in the directory: /vobs/somePath/myDir.
I execute the command below in the directory:
cleartool ls -l
And I do get some view private object files.
What I need is to recover this directory with my baseline, which has been set before. Besides, I have some uncheckin files in other paths and I don't want to check them in right now. In other words, I just want to recover the directory myDir and don't touch any other files.
How to achieve this?
For a dynamic view (/vobs/avob/myview/...), only private files are writable, so you can delete everything and it will only delete the private ones.
But, if you have checked out files (which should not be deleted), or if you don't want to risk anything, you can clean just the private files with, using cleartool lsprivate:
cd /vobs/somePath/myDir
ct lspriv . | grep -v checkedout | xargs rm -rf

Clearcase Element existence

I want to check with a batch file if a certain element is already existent in Clearcase, or if I still have to add it.
How can I put this into a conditional statement?
Like:
if cleartool exists myFileName do myaction
else doOtherAction
You need to build a function which returns true or false depending on the element full name being part of the ClearCase view elements or not.
Then you can call that function from your if... else... statement.
Here are various commands that your function could use in order to determine if a file is a ClearCase element (meaning already added to source control) or not:
You can start by using the result of cleartool ls -l: if its output includes view-private object, it isn't added to source control yet.
cmd-context ls -long
version Makefile##\main\3 Rule: element * \main\LATEST
view private object bug.report
version cm_add.c##\main\0 Rule: element * \main\LATEST
derived object (unshared) hello##2007-03-24T11:32.418
version hello.h##\main\CHECKEDOUT from \main\2
Rule: element * CHECKEDOUT
Here 'bug.report' isn't added yet.
See more at "About view-private objects".
I already recommended that approach for a previous question using C#: "c# How to determine if a file is in ClearCase?".
Another approach is to use cleartool describe, which would trigger an error if the element described is a private one.
As mentioned in the technote "How to list view-private files in a view in Rational ClearCase", the command cleartool lsprivate works only in dynamic views, not in snapshot views.
For snapshot view, you can use: cleartool ls -r -view_only
Another approach is to use cleartool find, as in "Clearcase: How do I check if an element has a version on the trunk that was created after I branched off from the trunk?"
The following DOS batch file will add a file to ClearCase if it's not in there yet. Works in both dynamic and snapshot views.
#ECHO OFF
cleartool ls -l %1 | FIND "view private object"
IF %ERRORLEVEL% == 1 GOTO END
cleartool co -nc .
cleartool mkelem -nc -ci %1
cleartool ci -nc .
:END
You may want to add suitable comments instead of using the -nc switch.

Trying to undo a cleartool rm

I was trying to migrate a file from directory A to directory B in a branch, call it file.txt. What I did was:
cd A
cp file.txt ../B/
ct rm A
cd ../B
ct mkelem -ci -nc file.txt
Thereby losing all the history. I am trying to recover from this to do what I should have done which is simply ct mv file.txt ../B
I read that for this I should do something like this:
cd A
ct ln .##/main/?/file.txt ./file.txt
where luckily, from another view, I've figured out ? should be 27. Unfortunately when I try to do the above I get:
cleartool: Error: Entry named "file.txt" already exists.
cleartool: Error: Unable to create link: "./file.txt".
and I try to do:
ct rmelem file.txt
but got:
cleartool: Error: Element "file.txt" has branches not created by user
though presumably that's not what I should be doing anyway. How do I get back that file? It was simply a ct rm. I even get the entry already exists error if I do ct rm on the new copy file I added to directory B..
You are on the right track, but I would recommend a simple rmname, instead of a rmelem (which deletes the element with all its versions, branches and such).
That would remove file.txt from the latest version of the parent directory, and allows you to proceed with the symlink.
Next time, a cleartool mv might be easier, and keep the history of the file being moved.

Can't see directory/Can't uncheckout

When I do "ct lsco -a" I can see that I have three checkouts. But they don't show up in xclearcase, and the directories aren't visible from the command line.
ct lsco -a | grep hendrixjl
--07-29T15:32 hendrixjl checkout directory version "/vobs/CORE/CORE_APPS/src/mapmgr_decoupled##/main/rel_core_0.5.0.0__int/fea__cr_54__0.5.0.0_decouple_map_manager/3/icondetails_decoupled" from /main/rel_core_0.5.0.0__int/fea__cr_47__0.5.0.0_ui_decouple/0 (unreserved)
--07-29T15:32 hendrixjl checkout directory version "/vobs/CORE/CORE_APPS/src/mapmgr_decoupled##/main/rel_core_0.5.0.0__int/fea__cr_54__0.5.0.0_decouple_map_manager/4/overlays" from /main/rel_core_0.5.0.0__int/fea__cr_47__0.5.0.0_ui_decouple/0 (unreserved)
--07-29T15:32 hendrixjl checkout directory version "/vobs/CORE/CORE_APPS/src/mapmgr_decoupled##/main/rel_core_0.5.0.0__int/fea__cr_54__0.5.0.0_decouple_map_manager/4/overlays/main/rel_core_0.5.0.0__int/fea__cr_54__0.5.0.0_decouple_map_manager/1/images" from /main/rel_core_0.5.0.0__int/fea__cr_47__0.5.0.0_ui_decouple/0 (unreserved)
[hendrixjl#BA-JBCP-HENDRIX CORE]$ cd /vobs/CORE/CORE_APPS/src/mapmgr_decoupled
[hendrixjl#BA-JBCP-HENDRIX mapmgr_decoupled]$ ls
Makefile ascope_translator common_decoupled displaySA_decoupled filters mgr_decoupled unit_test
[hendrixjl#BA-JBCP-HENDRIX mapmgr_decoupled]$ ct unco .
cleartool: Error: No branch of element is checked out to view "cc-svr:/data/cc_store/viewstore/hendrixjl/fea__cr_47__0.5.0.0_ui_decouple__hendrixjl_view.vws".
cleartool: Error: Unable to find checked out version for ".".
[hendrixjl#BA-JBCP-HENDRIX mapmgr_decoupled]$ ct unco icondetails_decoupled
cleartool: Error: Element name not found: "icondetails_decoupled".
[hendrixjl#BA-JBCP-HENDRIX mapmgr_decoupled]$
Those directories are checked-out in parent directories which are not visible/selected by your current view, probably because they have been removed (rmnamed).
That means the checked-out versions are not accessible from this view.
However, a potential workaround is to search for those same checked-out directories from the GUI "find checkouts" window: there you can select the checked-out element (file or directory) and select "undo checkout".
Another workaround is to go to the full extended path of that directory in a dynamic view: you will then be able to "cleartool unco" the directory.
cd /vobs/CORE/CORE_APPS/src/mapmgr_decoupled##/main/rel_core_0.5.0.0__int/fea__cr_54__0.5.0.0_decouple_map_manager/3
cleartool unco icondetails_decoupled
In any case, whenever you don't see an element, the first think to do is a version tree of the parent directory of that element, in order to check if the missing element has been rmname'd in one of the version of said parent directory.

Recursive checkin using Clearcase

I want to check in a directory and all the sub-directories into the clear case.
Is there a specific command to achieve it?
Currently I am going into each directory and manually checking in each file.
I would recommend this question:
Now the problem is to checkin everything that has changed.
It is problematic since often not everything has changed, and ClearCase will trigger an error message when trying to check in an identical file. Meaning you will need 2 commands:
ct lsco -r -cvi -fmt "ci -nc \"%n\"\n" | ct
ct lsco -r -cvi -fmt "unco -rm %n\n" | ct
(with 'ct being 'cleartool' : type 'doskey ct=cleartool $*' on Windows to set that alias)
But if by "checkin" you mean:
"enter into source control for the first time"
"updating a large number of files which may have changed on an existing versionned directory"
I would recommend creating a dynamic view and clearfsimport your snapshot tree (with the new files) in the dynamic view.
See this question or this question.
the clearfsimport script is better equipped to import multiple times the same set of files, and automatically:
add new files,
make new version of existing files previously imported (but modified in the source set of files re-imported)
remove files already imported but no longer present in the source set of files.
make a clear log of all operations made during the import process.
:
clearfsimport -preview -rec -nset c:\sourceDir\* m:\MyView\MyVob\MyDestinationDirectory
did you used -recurse option in the clearfsimport command.
Example: clearfsimport -recurse source_dir .
This should help.
If you're using the Windows client, right-click on the parent folder, select Search, leave the file name field empty, click Search, select all the files in the result window (ctrl-A), right-click on them and select ClearCase -> Add to Source Control
If you are in windows you may try,
for /f "usebackq" %i in (`cleartool lsco -cview -me -r -s`) do cleartool ci -nc %i

Resources