Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test whether file at path exists in repo?

Tags:

perforce

Given a path (on my computer), how can I test whether that file is under version control (ie. a copy exists in the Perforce depot)? I'd like to test this at the command line.

like image 908
Colonel Panic Avatar asked Oct 29 '13 15:10

Colonel Panic


2 Answers

For scripting, p4 files FILE is insufficient because it doesn't change its exit code when there is no such file.

Instead, you can pass it through grep, which looks for perforce paths' telltale pair of leading slashes:

# silently true when the file exists or false when it does not.
p4_exists() { 
  p4 files -e "$1" 2>/dev/null |grep -q ^//
}

You can get rid of the 2>/dev/null and grep's -q if you want visible output.

Before p4 files version 2012.1 (say p4 files version 2011.1), it didn't support -e. You'll have to add |grep -v ' - delete [^-]*$' before the grep above.

⚠Warning: A future p4 release could change the formatting and break this logic.

like image 25
Adam Katz Avatar answered Sep 21 '22 02:09

Adam Katz


Check p4 help files. In short, you run p4 files <your path here> and it will give you the depot path to that file. If it isn't in the depot, you'll get "no such file(s)".

like image 168
Mark Avatar answered Sep 18 '22 02:09

Mark