I know that generally, when running p4 changes you need a clientspec specified, so that Perforce can limit the results properly.
Yet, in P4V, you are allowed to operate in a "no workspace selected" mode, and you can view changes, etc.
I want to do something similar from a script, but the only way I can think to accomplish this is to:
Create a temporary clientspec, with some general //depot/... mapping
Perform my operations (eg: p4 changes blabla)
Delete the temporary clientspec
But I don't want to have all these temporary clientspecs being created/destroyed all the time. P4V doesn't seem to be doing that in its "no workspace selected" mode.
Is there a way to acomplish the same, from the commandline?
Your client spec doesn't matter at all if you provide a depot path to the "p4 changes" command. Just run:
p4 changes //depot/...
or whatever command you were going to run with your temporary "//depot/..." mapped client spec.
Your client spec will ONLY come into play if you use an argument that is explicitly client-relative, such as a local file path, the #have revision specifier, et cetera. If you don't use a client-relative argument, it doesn't matter if your clientspec is undefined, if it maps only one file, or if it maps the whole world, you'll get the same results from "p4 changes" regardless.
Related
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.
P4D/LINUX26X86_64/2013.2/938876 (2014/09/23)
I had some changes in the default changelist that I tried to shelve. It said I couldn't because I needed to resolve with some other changelist. It stuck my files in some other changelist. After looking at the differences, I saw that I wanted to keep all my changes and accept nothing from the other changelist. Thinking that "-am" meant "accept mine", I ran "p4 resolve -am". Then there was a "Duuuuhhhhh" momemt when I remembered that "-am" means "auto-merge".
Q: How can I "undo" the automerge that just happened so as to restore what I had ?
If you were able to shelve successfully at some point you can get the pre-resolve files back from the shelf via "p4 unshelve".
As a general rule you can't undo the results of a resolve operation to get the "yours" file back, since the workspace file isn't backed up anywhere.
Since this was an automerge, one option would be to try to run the merge in reverse. You started with A(base)+AB(theirs)+AC(yours), and now you have ABC(merged) -- so you want to set up a merge that'll produce AC. That'd be AB(base)+A(theirs)+ABC(yours)=AC(merged) -- basically you want to find the "base" and "theirs" from the automerge and reverse them, using the merged result as "yours". Run "p4 resolved -o" to find the "base" and "theirs" file from the previous merge, then run "p4 print" to get those file contents and use "p4 merge3" to run the 3-way merge algorithm with the three appropriate inputs and the output should be your original file (in theory).
If I have a workspace open in P4V and I switch workspaces is there a way to notify or detect that the switch has happened externally?
The workspace contains an editor and needs to checkout files to modify them. I'm worried that a switch via P4V would leave the editor unaware that the files are now from a different stream.
I would rather have a way to detect this in the editor rather than having to notify from P4V if possible.
Thanks,
Alex
Are you saying your editor checks out the files automatically? That's common, so you're not on your own. What editor is it, if I may ask?
Do you know how your editor talks to Perforce? Am I right thinking that it issues p4.exe (the cmdline tool) commands, e.g. p4 edit? (The other way would be using one of the P4 APIs, e.g. p4java or p4python.) If so, the p4 edit commands already do not respect the P4V workspace setting. The p4.exe cmdline tool will work with the p4 workspace specified in one of six ways. To always use the right client,
have a P4CONFIG file specifying P4CLIENT=[client name] in the root of each of your workspaces
change the p4 integration of your editor in such a way that the p4 edit command will always be run effectively from within the given workspace (in the sense of CWD); you can use the -d switch for this, e.g. when checking out C:\workspaces\wksp1\foo\bar\baz.c you would call p4 -d C:\workspaces\wksp1\foo\bar edit C:\workspaces\wksp1\foo\bar\baz.c.
If the user is using a new workspace, they will also be working with a different set of files, so there's hopefully not much chance for confusion there. (Unless they've made multiple workspaces with the same Root, in which case they're doing their very best to shoot off their own kneecaps.)
If they've switched streams within the current workspace, you can detect this with a command like "p4 info", "p4 client -o", or "p4 stream -o".
I have a few files that have been edited by an external IDE, I forgot to Check Out the files before making the changes however when I look at the files through P4V the files have changed but the indicator for the file itself shows as nothing has changed. How can I ensure my changes are committed without loosing what I have done?
One way I was thinking was to making a copy of the file, revert, check out, copy content or replace file.
That is OK with a few files but what happens when you have done so with hundreds of files?
The "check out" command doesn't modify the local file, so you can just do that on its own without having to make a backup copy of the file first. (What you want to avoid doing is "get latest", although if the local files are writable, Perforce will automatically balk at updating them by default because of this exact situation.)
If you have lots of files that might or might not have been modified in different ways, use Actions > Reconcile Offline Work, or "p4 reconcile" from the command line. This will find the locally modified files and open them for the appropriate action.
The P4V way to do this is called "Reconcile Offline Work": http://www.perforce.com/perforce/doc.current/manuals/p4v/Offline.html
Or, at the command line, you can use 'p4 reconcile': http://www.perforce.com/perforce/doc.current/manuals/cmdref/p4_reconcile.html
I'm trying to open an existing Perforce application. I made some local changes, like deleting files, which I want to undo (that is, I want my local copy to exactly match the repository once more -- delete added files, restore deleted files, and undo changes).
When I try to revert using the p4v gui client, I see this error:
file(s) not opened on this client
What am I doing wrong?
I did manage to revert all the changed files, but not the added/removed files.
Edit: I did the following:
Connect to a Perforce server using p4v
Map a directory to my local file system (lets say C:\Perforce)
Get the latest version of the repository
Go to C:\Perforce in Windows Explorer
Delete some files and folders
Add some files and folders
I would like to get back to the "pristine" state, the copy of exactly what's on the server when I got the latest version of the repository for the first time.
By the looks of the edited description you added and deleted files directly on the filesystem and not through perforce. Therefore Perforce doesn't know anything about those changes so there is nothing to revert. Typically when you want to add a file you use 'p4 add" (or the equivalent p4v operation), and when you delete, you should use 'p4 delete' (or again, the equivalent p4v operation).
Really, the best option to get back to a pristine state is to nuke the local copy of the code in c:\perforce (in windows explorer), go to p4v, right click the area you want to sync, and choose "Get Revision..." and in the subsequent dialog, make sure that the "force operation" checkbox is checked. This will tell Perforce that you want a new copy of everything regardless of whether you had it synced or not.
You can also run "reconcile offline work" in p4v. Right click the depot area and choose that option. It will scan through the local folder structure and give you a report of what files have been added that don't exist in perforce, what files were deleted, and what files were modified. From that dialog, you can right click on local files that don't exist in perforce and delete them, or you can 'p4 add' them. You can also sync deleted files.
HTH.
Just an extra not to point out another cause for this.
If the file name contains an unusual character that cannot be translated correctly the name on the client will never match that on the server.
The solution in this case is to spot that character in the file name (it will be a question mark emblem on Linux) and use a wildcard to help identify the file to the server so it can delete it etc (p4 deleting the file is a way to go).
This answer may not be your case. This happened to me when I edited the files on my local disk without logging into p4.
A quick fix at commandline is:
p4 login # make sure you've logged in
p4 edit <filename> # let p4 know you've edited the file
p4 revert <filename> # revert to "pristine" state
You can use p4 reconcile -w to restore your client to the state of the server. There is an alias called clean, which is also available in P4V on the right-click context menu as Clean....
There are several additional flags to control whether added and deleted files are deleted or restored, respectively.
The -w flag forces the workspace files to be updated to match the
depot rather than opening them so that the depot can be updated to
match the workspace. The -a, -d, and -e flags when used with -w
update workspace files as follows:
-a Files with no corresponding depot file are deleted.
-d Depot files not in the workspace are added.
-e Modified files are restored to the last version synced.