Search code examples
version-controlclearcasedifference

cleartool find difference recursive in certain file type to predecessor


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


Solution

  • 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.