1

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

airborne
  • 3,664
  • 4
  • 15
  • 27
  • It is better to not use wildcard for your cleartool diff, but rather combine a find query: I'll post an answer later today – VonC Jun 30 '17 at 09:10
  • What is the underlying purpose of the request? If you're running this as a scheduled job to trigger a build, this would be returning "it changed" almost every time if all the files in question are checked in. (Unless checkin -identical is a normal occurrence in your location.) – Brian Cowan Jun 30 '17 at 17:00

2 Answers2

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

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.

Brian Cowan
  • 1,048
  • 6
  • 7