Automatically deleting newly added files when shelving in Perforce - perforce

When I shelve a pending changelist, changes to existing files are reverted, but newly added files are not deleted from the filesystem. I need to manually delete these files every time I perform a shelve operation. Is there anyway to automatically delete newly added files when shelving?

in p4, if you're willing to make it two operations, you can do a normal shelve on the changelist, and then do p4 revert -w on the same changelist, which deletes added files. i'm not sure how to do this in p4v.

It looks like P4V added this in a recent release!
https://www.perforce.com/perforce/doc.current/user/p4vnotes.txt
#40757 (Changes #1619278, #1618572)
The Shelve Dialog has an option to remove the files from disk that are marked for
'Add'.

To do this in p4v, you can create a custom tool, say "revert-added-file-and-delete", adding it to applicable context menus, with application p4 and arguments revert -w %F.
Unless someone knows of a way to chain custom tools together (and I couldn't find a way to do it), to do a shelve/revert will require a separate shelve followed by a use of the custom command, revert-added-file-and-delete.

Sure, except that shelving work is a fundamentally different beast. If I create a new class that uses a new function in an existing class, and then shelve both files, the new class remains, and is now referencing a non-existent function in the existing class. Now I've got build errors and have to manually delete the new file in order to get back to a clean slate, which is exactly what shelving work should do for me.

p4 shelve -c changelist_number
p4 revert -w -c changelist_number //...

I don't think that there is a way to do this. This behavior is consistent with reverting files that have been added. If you 'p4 add' a file and then revert it, it will not be deleted on revert. Seems like it would be bad behavior if it did! Losing a file and the work that has gone into the file on a revert would be very bad. Consider this: you code up a file in your editor, you save diligently, and finally you are ready to 'p4 add' it to perforce. Then you decide you don't want to do this so you revert and then you lose your file???
So reverting adds won't delete the file.

Related

P4V Get Latest does nothing

I do not want to go "Get Revision" > "Force". Because half of my stuff is already downloaded. I don't want to overwrite what I already have. P4V Can clearly see that what is in the depot and what is local is completely different. How can I get Perforce to retrieve the files I do not have, and ignore the ones I already do?
Select your workspace root, go to File > Open Command Window Here, and run:
p4 clean
This will scan your workspace and force-sync everything that's different or missing, as well as deleting unadded files. Note that if you have local work that isn't in a changelist, this will irrevocably erase it. If you only want to "clean" files that are edited/present but out of date (and disregard added/deleted files), do p4 clean -e instead. If you want to preview the operation before doing it for real, do p4 clean -n.
I think you can do the equivalent via the "Reconcile Offline Work" tool in P4V, but it may require additional manual steps.
To make working with Perforce easier, try to avoid modifying files in your workspace that are read-only -- if you want to remove a file from your workspace, use "remove from workspace" in P4V rather than manually deleting it, etc. Perforce is able to make file operations very fast by virtue of knowing what's in your workspace and not having to re-check it each time, but you eliminate that benefit when you mess with your workspace manually.
Instead of p4 clean, you could do:
reconcile offline work on root of workspace then a pop-up saying that you deleted some files and it is going to delete them from Depot of the server as well make sure you added to default or new changelist or whatever. Accept.
Go to changelist and right-click press revert files to bring back the deleted/missing files.

Make the contents of a perforce directory exactly match the latest depot version

I would like to make the contents of a directory in a Perforce workspace be exactly the same as the latest depot contents. I want this to work no matter what has gone on in the workspace. (For example, editing files without opening them in perforce, creating unsubmitted changesets, etc.)
So far I have come up with running this series of commands, in order:
p4 clean ...
p4 revert ...
p4 sync ...
Will this do what I want? Is this the correct order? Is there a simpler way?
Those are the correct commands, and you do need all three:
revert is needed to discard changes to files you've opened
clean is needed to discard changes to files you haven't opened (including added files)
sync is needed to make sure you're at the very latest depot revision
You should either put clean after the revert or add -w to revert; otherwise files that were opened for add will be skipped by the clean (because they're open) and then revert will "abandon" them in the workspace (the -w option causes revert to delete/"wipe" added files instead of abandoning them). Other than that, I think the order is unimportant.

Accidental mark for delete - entire depot and reverting - perforce ..How to remove that tag(Mark for delete) from all files

Whole workspace files marked as delete in local also and depot also.
Depot contains thousands of file ..While reverting file options P4 get's hanged..
Any Solution for this ...help me...
Thanks in advance.
When P4V hangs on these mass commands, I prefer using the command-line. In this case, p4 revert //depot/path/to/the/workspace/....
Make sure you don't actually revert things you want to keep though.

p4v doesn't delete new files added through `p4 add` after shelving

I've tried to shelve files today and checked the Revert checked out files after they are shelved option, and after shelving the files some files have been reverted, but some remained. It appeared that these were new files added through p4 add. Is it default behavior to not remove such files after shelving? Is there a way to remove them as part of shelving process?
What you did in P4V (shelve with reverting) is really a plain combination of two commands: shelve and revert. Behind the scenes, P4V will shelve your work (as it surely did) and then revert everything in your changelist.
Now, the revert command reverts p4 adds in such a way that they disappear from your changelist (the essence of reverting) but they remain on the local filesystem (to prevent inadvertent loss of code/data). Yes, you can argue that in this respect revert does not do a very good job of reverting your work completely, but obviously Perforce have decided to play it safe by not deleting your work.
As #Bryan Pendleton says, you can use p4 revert -w instead of plain p4 revert when you want to also delete your p4 adds from the filesystem. It's not a separate command, just a variant of p4 revert. However, there's no way to specify the -w flag (the -w behaviour) when running the "Shelve-and-Revert" combo action from P4V. (In fact, there's no way to specify -w even in the plain "Revert" action from P4V.)
I'm assuming you won't switch from P4V to the command-line (to run p4 shelve followed by p4 revert -w) just for this reason, so just remember that P4V has this little quirk and if needed, delete your local files after reverting them.

Perforce Change List too Big

In Perforce, I have created a change list that has over 200,000 files (by doing a rename on a directory). This change list is now too big to submit or revert. When I try, I get an error saying that the operation took too long.
I am now stuck with this change list that has my original directory in marked for delete state and a new directory that hasn't been submitted. Is there a way undo this change list?
You can revert the files a few at a time. As a test, you could run p4 revert //path/to/some/file and verify that it's able to revert that file.
Once you know that's working, you just need a way to automate the process.
You could script something up that starts in the root directory and runs through all directories breadth-first, running p4 revert //path/to/folder/* at each folder (I think you could also use client paths).
You can revert via the command line using the p4 tool. I do not think you can revert the files from the UI. The associated documentation shows various examples of how revert all or specific files (see the Examples section):
http://www.perforce.com/perforce/r12.1/manuals/cmdref/revert.html

Resources