I do have a script with check the format/style of the files. We used to run it on all elements every night using sort of night_script.
Now I want to add it to a preop trigger for checkin command. To do that per file(s) a switch is needed. How could I do so?
Example of how the script runs:
style_check -f file1 [file2 ... fileN]
I found this trigger creation command while searching but I don't know how to customize it :)
#execute a script on all text files after checkin:
ct mktrtype -element -all -preop checkin -eltype text_file -exec <path to script> PROCESS_CHECKIN
See "Is it possible to lock the applying label option for a work_branch in ClearCase?" for an example of preop trigger:
ct mktrtype -element -all -preop mklabel -exec "/path/to/script"
See also the Examples section of cleartool mktrtype
The trick is to use a shared path accessible by all ClearCase client workstations.
check the "Trigger operations and trigger environment variables" to find the right variable to pass as parameter to your script: in your case, CLEARCASE_PN
ct mktrtype -element -all -preop mklabel -execwin "\\path\to\script \"%CLEARCASE_PN\"" and -execunix "/path/to/script $CLEARCASE_PN"
Note the use of -execunix/-execwin to reference the same script (or a different script) per OS.
Related
I am working on a script that will update a bunch of files in a given ClearCase folder. Before to start, I want to check in the script if any checkout that will be performed during the process may fail (because of another checkout). The script does not know the config spec in use.
The basic idea based on cleartool lsco -rec cannot work because of the many false-positive result (mostly, checkout done on a not selected branch, or unreserved checkout).
So the question is: How can I list all file that I cannot checkout because of another checkout that will conflict with mine?
Thanks in advance for your help!
"The basic idea based on cleartool lsco -rec cannot work"
Yet it should work.
You can compare cleartool lsco -brtype abranch -me and cleartool lsco -brtype abranch in order to see other checkouts done on the target branch, not by you.
You can |grep -v unreserved to trim out any unreserved checkout.
The end result is the list of files, checkout not by you, reserved.
You can then compare that list with the files your script has to modify.
If you're using a classic-UCM environment, this would generally not happen if you're not working in a shared stream. So, I'm going to assume you are working in base clearcase.
One way to check this would be to look at the version trees of the files you plan on checking out. However, to automate it, you would need to also know what branch you're working on.
For a single file:
Windows:
cleartool lsvtree {my file} | findstr CHECKEDOUT
Unix
cleartool lsvtree {my file} | grep CHECKEDOUT
Any CHECKEDOUT returns on your branch (which may be /main if you're not doing parallel development) would block you.
If you have a list of files, it would depend on how you want to process that list.
In my script I'm calling ClearCase to check if any file of a certain file type in the current path (including all subfolders) has been changed. I'm not familiar with cleartool at all, the command should like this:
cleartool diff -predecessor -recursive *.filetype
As a return value I only need a bool: true if any differences exist, false if nothing has changed
As a return value I only need a bool: true if any differences exist, false if nothing has changed
You need a script. A simple find + exec won't be enough, because the exit status won't be exactly what you need.
#! /bin/bash
noChange=0 ### "cleartool diff" exit status means no difference
files=$(cleartool find . -name "*.filetype")
for f in ${file}; do;
cleartool diff -pre -options "-status_only" "${f}"
if [ $? != $noChange ]; then
exit 0
fi
done
exit 1
(0 is true, false is 1 in shell)
Note the use, in cleartool diff of the -options parameter:
opt/ions pass-through-opts
Specifies one or more compare method options that are not directly supported by diff.
That way, you get only the status from cleartool diff, which is precisely what you want to test in your case.
Since your previous question shows you have Git too, you can easily execute that script in a bash session, even on Windows.
On first glance, the command you're looking for is something like this:
cleartool find . -name "*.filetype" -exec 'cleartool diff -pred "$CLEARCASE_PN"'
On windows, it would look like this:
cleartool find . -name "*.filetype" -exec "cleartool diff -pred \"%CLEARCASE_PN%\""
The single quotes in the Unix example are significant since otherwise the "CLEARCASE_PN" environment variable reference would be expanded at the time you start the command and not when the -exec is actually fired.
The \"%CLEARCASE_PN%\" construct in the Windows command line and the "$CLEARCASE_PN" on unix is to account for filenames including spaces.
Now, looking at what you want... I'm not sure it would accomplish the underlying purpose, whatever that is.
I have been asked to find every checkin by one specific user across an entire ClearCase Project VOB since a particular date. How might I obtain this information?
I assume it's some usage of the cleartool find command, but I've not yet figured out the syntax to get the information that I'm looking for.
I guess I'm looking for a "change set" across every activity of that user across every stream of a given PVOB since a particular date.
Looking at cleartool find (which work for versions created with or without UCM), it should be something like:
cleartool find . -user <auser> -version "{created_since(date1)}" -print
This is done within a vob, not a pvob, as it search for version (data), not UCM activities (metadata recorded on PVob level)
You need first to go to a view, preferably a dynamic view:
cd m:\aView\aVob
# unix
cd /view/aview/vobs/avob
As noted by the OP's answer, what works is:
using create_by instead of -user,
adding -all -nvis.
With the repeated help of (and huge thanks to) #VonC, here is what I wound up using, at a command prompt (not in a ClearTool session), with my working directory set to the directory just beneath the root of my snapshot view:
cleartool find . -all -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>
Update: The command below, which was originally my answer, returns only invisible files:
cleartool find . -all -nvisible -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>
I would like to write a little batch script, which I would use to collect all of the comments of a file on a specific branch. For example, if I have an ABC.cpp file under the myBranch branch and it has already 3 versions, I would like to have the comments from version 1, 2 and 3.
I still couldn't get multiple versions of the same file. I am using the "find" command of cleartool. Maybe it is not possible in a simple cleartool find command, so let me know, if that's so.
Thanks!
If is possible to list the version of a file, either with cleartool find (using the -ver), or with cleartool lshist.
For a specific branch:
cleartool find . -name "ABC.cpp" -ver "{brtype(myBranch)}"
For each file, you can access its content with cleartool get.
See also "In ClearCase, how can I view old version of a file in a static view, from the command line?"
cleartool find . -name "ABC.cpp" -ver "{brtype(myBranch)}" -exec
I want to check out all files in all subdirectories of a specified folder.
(And it is painful to do this using the GUI, because there is no recursive checkout option).
Beware: ClearCase is File-centric, not repository centric (like SVN or CVS).
That means it is rarely a good solution to checkout all files (and it can be fairly long with ClearCase ;) )
That being said, the question is perfectly legitimate and I would like to point out another way:
open a cleartool session in the 'specified folder':
c:\MyFolder> cleartool
cleartool> co -c "Reason for massive checkout" .../*
does the trick too. But as the aku's answer, it does checkout everything: files and directories... and you may most not need to checkout directories!
cleartool find somedir -type f -exec "cleartool checkout -c \"Reason for massive checkout\" \"%CLEARCASE_PN%\""
would only checkout files...
Now the problem is to checkin everything that has changed. It is problematic since often not everything has changed, and CleaCase 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)
Note that ct ci -nc will check-in with the comment used for the checkout stage.
So it is not a checkin without a comment (like the -nc option -- or "no comment" -- could make believe).
cleartool find somedir -exec "cleartool checkout -nc \"%CLEARCASE_PN%\""
Also an article "ClearCase: The ten best scripts" might be helpful