Clearcase: Check if new baseline exists - clearcase

I am writing a windows batch script which has a if condition that checks if a new baseline was created i.e. if any new changes were submitted.
I tried:
SET REBASE_RETURN="No rebase needed"
SET FLAG=true
for /f usebackq %%F in (`cleartool desc -fmt %%[latest_bls]Cp\ stream:%INTSTREAM%#\%PVOB%`) do (
cleartool rebase -baseline %%F#\%PVOB% -complete | findstr !REBASE_RETURN!
IF ERRORLEVEL 0 SET FLAG=false)
But this is not working as i expected.
Is there a way i can run a clearcase command, just to get a boolean or some return value. So that i know if a new baseline was created.

You should:
get the foundations baselines of the current stream (from fmt_ccase)
cleartool descr -fmt "%%[found_bls]CXp\ -cstream
for each baselines from Int, check if it is present in the current foundation baselines of Dev.
See "Batch file: Find if substring is in string (not in a file)".
For the current baseline: list all the baselines of a stream and take the latest.
cleartool lsbl -stream aStream#\aPVob -component aComponent#\aPvob|tail -1
(with tail.exe coming from the Gnu On Windows)

Related

How to obtain previous baseline from stream

I can retrieve latest baseline which is always recommended in my case using following command
"cleartool desc -fmt \"%[rec_bls]CXp\" stream:".$SourceStream."\#\\".$pvob
I want to retrieve second latest baseline.Is it possible to obtain previous baseline from a given stream using cleartool command? previous applied baseline on any given component will also works.I need this to get difference between two streams from different projects which can be done by following command.
"cleartool diffbl -elements baseline:".$LastComponentBaseline." stream:".$CurrentStream;
You can start by looking at the output of cleartool lsbl: it does list (for a given stream and/or component).
Combined with fmt_ccase, you can grep the recommended baseline you know, and the line before, since lsbl lists baselines from the oldest to the newest
cleartool lsbl -fmt "%[component]Xp %n" -stream aStream#\aVob | grep -B 1 -E "yourComponent.*yourBaseline"
You need to grep for the right component name (displayed by the %[component]Xp format), as lsbl (on a stream) would list all baselines of all components.

Getting previous activity ids of a file in clearcase commandline

I'm using windows. I need to extract activity ids of check ins in ClearCase.
I can get the current one through cleartool describe and then parsing the response for the word 'Activity'.
I'm looking to get the activity ids of it's previous versions.
How can I do that?
You don't have to parse the output of cleartool describe, if you combine it with fmt_ccase.
That allows you to:
get the previous version of an existing version
cd /path/to/view
cleartool describe -fmt "%[version_predecessor]p" afile
get all activity id with that version involved:
cd /path/to/view
cleartool describe -fmt "%[activity]p" afile##/a/previous/version
(that is using the version-extended pathname ##/... returned by the first cleartool describe)

What is the Cleartool command to undo check out if it is identical?

I checkout a powershell file and signing it if it is not signed already then check-in back.
But my check-in fails as saying identical to predecessor. What is the cleartool command to undo checkout if it is identical to previous version?
You can simply try:
cleartool unco
That is "undo checkout"
Now you cannot do that in the checkin command itself.
What you can do is a cleartool diff: if there is no difference detected, then you unco, if there are, you check in.
You have that approach detailed in this thread:
You may need to diff against the previous version, but you can use something like diff <file> <file>##/main/branch/version, and if different (or whatever that diff returns if they are different), then allow the checkin to succeed). Otherwise maybe unco -rm the file.
Or:
In our makefile we have a section that basically follows the following format for each file:
call checkin_if_changed.bat "dir1\sub\file.h"
The contents of the file "checkin_if_changed.bat" are as follows:
cleartool diff -pre -dif %1
echo File: %1 diff result: %ERRORLEVEL%
goto diff%ERRORLEVEL%
:diff1
cleartool ci -c "Build box build." %1
goto end
:diff0
cleartool unco -rm %1
:end
Basically we do a cleartool diff against the prev version of the file.
If the cleartool diff returns a 0 it means the files are identical, so we do an unco -rm.
If cleartool diff finds a difference it returns a 1, meaning the files are different, and we check it in.
Or:
I've used the somewhat messy:
cleartool lsco -cvi -avo -fmt "ci -nc '%n'\nunco -rm '%n'" | cleartool
If the file is identical (and fails the checkin), then it unchecks it
out.
If it isn't identical, it checks it in, then the unco command
fails (since it's not checked out) with an error (but continues).
You can dump all of the output to a log file if you don't want to see it on
the command line. You can probably refine that if you need to.
If you have a post checkin trigger that forces you to enter a comment, then
change the -nc to -c 'some comment' instead.

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.

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