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.
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.
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)".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With