Ruslan
Ruslan

Reputation: 113

How to detect if folder is under Perforce/ source control

I need to find out if file/folder is under specific source control. The easiest way of doing this is to find some hidden folders. (this does not guaranty that partifical file is under source control, but with some probality says that this source control was used )

It's quite straightforward with SVN, GIT, as they have hidden folders.

But I can not find the same things for Perforce and ClearCase. Are there any universal way to understand what VSC is used in those paricular cases?

Upvotes: 1

Views: 1240

Answers (3)

William
William

Reputation: 4935

If you need to script it for Perforce, there is an option (-s) that makes things easier (since the exit code of p4 doesn't indicate success or failure of the Perforce command). So, for bourne-like shells something like this should work:

if p4 -s fstat FILENAME | grep 'exit: 0' >/dev/null 2>&1 ; then
  echo "Perforce knows this file"
else
  echo "Perforce don't care"
fi 

Upvotes: 1

VonC
VonC

Reputation: 1324073

For ClearCase, you will find a hidden file named view.dat at the root directory of a (snapshot) view .

If the file is under M:\ (Windows) or /view/vobs (Unix), no need to look for an hidden file or directory: you know it is a dynamic view.

Another way is to execute, in the parent directory of a file:

cleartool lsview -cview.

If that directory is in a view, that command will return its name.

Similarly, i you can run a command like p4 reconcile or p4 status, and it doesn't return an error, chances are you are in a Perforce workspace.

Upvotes: 0

JasonD
JasonD

Reputation: 16582

Perforce does not litter the drive, but keeps the info on the server. Also, files can be mapped in different structures, and mixed with non-controlled files, so it's not something you can determine by looking at the file itself.

However you can simply ask Perforce. For example, at the CLI:

P4 fstat FILENAME

Will give you info about a file if it is under source control.

Upvotes: 2

Related Questions