In perforce how can I delete files from a directory in my workspace where the files are not part of the workspace?
In perforce how can I delete files from a directory in my workspace where the files I want deleted are not part of the workspace?
I have a directory on my file system with files it gets from perforce but after some processes run, it creates some new files in those direc开发者_如何学编程tories.
Is there a perforce command to remove these generated files that are not part of my workspace?
Perforce 2013.2 has a p4 status
command, which is an alias for p4 reconcile -n
I don't know if it was available in earlier versions.
This is my quick implementation of p4 nothave
.
#!/bin/bash
#
# List files present, but not in perforce.
tmpd="$(mktemp -d /tmp/nothave.XXXXXXXX)"
trap "rm -rf $tmpd" EXIT HUP INT QUIT TERM
p4 have | awk -F' - ' '{print $2}' | sort >$tmpd/have.txt
root=$(p4 info | awk -F': ' '$1=="Client root"{print $2}')
find $root -type f | sort >$tmpd/find.txt
comm -13 $tmpd/have.txt $tmpd/find.txt
This will produce a list of files, which can then be piped into xargs rm
in order to be deleted. Be careful to inspect the list before deleting though. You may well find things you didn't expect in there.
You can also use the "Reconcile Offline Work" option in p4v and p4 to accomplish this without any scripting. In p4v, right click any directory in Depot view and select "Reconcile Offline Work".
The middle pane will have "Local files not in depot". You can select any or all of these, right click and choose "Delete Local file".
Easy!
If using Linux/Unix, in the Bourne shell family, you can type
find . -type f | p4 -x- files 2>&1| grep "no such file" | cut -f1 -d" " | xargs rm
Similarly, for symbolic links, type
find . -type l | p4 -x- files 2>&1| grep "no such file" | cut -f1 -d" " | xargs rm
Above is letter 'el', not 'one'.
Whether there is an equivalent in Windows I do not know.
You cannot modify/delete files that are not part of your workspace from within perforce. You will have to write external scripts for that.
This is a little awkward in powershell, because p4 sends the can't-find-file message to the error stream rather than std out.
ps > $error.clear()
ps > dir | %{p4 fstat -T "haveRev" $_} 2>$null
ps > $error | %{$_.Exception.ToString().Split()[1]} | %{del $_}
The second line should produces errors such as "FILENAME.EXT - no such file(s)."
It can be a bit flaky if you have anything other than these exceptions in the error stream, so beware.
You can use p4 nothave
to determine the files that are not managed by perforce. Depending on the output of p4 nothave
you might be able to do p4 nothave | xargs rm
, but be sure to check the result of p4 nothave
before running that (so that you don't delete something important by accident).
精彩评论