How to change 'Alt roots' in perforce? - perforce

When issuing a p4 command e.g. p4 client no matter current working directory is inside or outside the perforce workspace, the command output is
Error: p4 client root is not '/workspace_dir'.
Please make sure that your Perforce workspace has the 'Alt roots' set to '/workspace_dir'.
P4V client works ok.
How can change 'Alt roots' setting?

Run the p4 client command to edit your AltRoots.
If you do not have multiple client roots (which is a pretty rare situation), you do not need to set the AltRoots field. The error you quote is not a Perforce error that I'm familiar with and may be some sort of wrapper script or trigger that is configured to expect an AltRoot for reasons that may not be sound. I'd check with your Perforce admin for clarification.

Related

Getting Perforce client workspace handling automated

I am trying to automate access to Perforce via it's command line utility.
Creating a new client workspace with p4 client and syncing works ok.
Now I am allowing users to overwrite user, host, port, stream, revision.
From the docs it is not clear to me when I have to execute which commands to get the client workspace files in sync with an edited client workspace spec.
What I currently do is once p4 client is through search for
Client mymachine not changed
in stdout and do a p4 sync -f should the message not appear.
Is there a better or more sane way to do this?
I tried executing e.g. p4 sync -s in hope that it would fail should local data be deleted but it seems that I misunderstood the option?
It is not clear to me how this relates to your question about workspaces:
Now I am allowing users to overwrite user, host, port, stream,
revision.
since only one of those is a property of a workspace. I'm going to disregard that statement for now but if it was significant I'd encourage you to post a follow-up clarifying what you mean by "overwriting" each of these properties.
To your question:
From the docs it is not clear to me when I have to execute which
commands to get the client workspace files in sync with an edited
client workspace spec.
If the client View is updated, all you need to do is:
p4 sync
If the client Root is updated, or any of the other options that globally affect how files are written to the workspace, such as allwrite or modtime, you will need to re-sync the entire client. Ideally this is done by doing:
p4 sync #none
prior to changing the workspace in one of these ways. The other option would be to do something like the following sequence:
p4 sync #none
p4 sync
p4 clean
to make sure that everything is rewritten, and that any stragglers (e.g. anything that the "sync #none" couldn't locate because the Root had changed but that are still mapped in the client view) are removed from the workspace.
I tried executing e.g. p4 sync -s in hope that it would fail should
local data be deleted but it seems that I misunderstood the option?
Deleting local data is a separate issue from editing the client spec, but for that the command you want is p4 clean rather than p4 sync -- you use sync to tell the server you want it to send you new revisions, you use clean to bring your workspace back in line with what the server already sent you.
The recommended/supported workflow is to always use p4 commands to manipulate the read-only files in your workspace -- so if you want to delete a local file, use either p4 sync FILE#none (to remove it from your workspace but not affect the depot) or p4 delete FILE (to open it for delete so that it will be deleted for everyone when you submit).

Perforce - switch to workspace from command line

I am asking how to switch from client1 to client2 where client1 belongs to stream1 and client2 belongs to stream2.
What I am looking for it to do the same as being in p4v and then right click on a workspace and selecting 'switch to workspace'
Note, that if your current workspace is client1 and you use:
p4 client -s -S //DEPOT/stream2
or
p4 client -s S //DEPOT/stream2 client2
it won't change the workspace in the p4v GUI.
There are several different concepts here.
You can have a single workspace, or you can have multiple workspaces.
Each workspace has its own root directory on your workstation, and its own copy of whatever files you have most recently sync'd.
If you have a single workspace, you can switch that workspace back and forth from one stream to another, by using the 'client -s' command to switch the stream to which that workspace is bound. This way, you can alternate between working on one stream, and working on another, using a single workspace. In the most recent versions of the Perforce server (2015.1+), there is even a 'p4 switch' command which makes this process simpler still.
Switching your single workspace from one stream to another on the command line using 'client -s' is the equivalent of dragging and dropping your workspace icon from the old stream to the new stream in the Stream Graph, more or less.
You can also have multiple workspaces, each with an independent set of files sync'd, and you can work with each workspace separately. On the command line, to switch from one workspace to another, you simply change the way that you tell the 'p4' command which client you want to use, which you can do with the P4CLIENT variable or the '-c' flag to the client. For example:
p4 -c client1 sync
vs
p4 -c client2 sync
tells the p4 client to sync first client1, then client2. Alternately, you can do:
p4 set P4CLIENT=client1
p4 sync
then
p4 set P4CLIENT=client2
p4 sync
to accomplish the same effect (switching between one workspace and the other at the command line).
P4V, however, has its own notion of the "current workspace", which is separate from the command line, and I don't believe that just changing your P4CLIENT variable is enough to perform the P4V operation of "right click on a workspace and selecting 'switch to workspace'".
The closest thing you can get to a command-line command which changes which workspace P4V considers to be the current workspace, I think, is to invoke a different copy of P4V from the command line, and specify a different client name when you do so, as described here: http://www.perforce.com/blog/100114/p4v-secrets-calling-p4v-command-line
But I think this will get you a new P4V window with the other workspace, rather than changing the current workspace of your current P4V window.
Another possibility you could try would be to use one of the Windows GUI automation tools, such as Autoit (https://www.autoitscript.com/site/), to create a script which will use the Connection menu on the menu bar and operate the Switch to Workspace... dialog via Autoit.

What is the safest method to bring a perforce client in a clean state?

I am new to perforce and trying to understand the following:
I would like to keep a debug client in my workspace. The idea is, before checking in anything in the main code depot, I would like to bring the CL in my debug client and run some qualification or regression to make sure that I'm not breaking anything. So, I want my debug client to always mirror the main code-repo.
Is "p4 sync -f" enough to ensure that- assuming that I don't have any opened (p4 edit/open/add etc) file in my debug client? Will force sync also overwrite the locally edited files (not p4 edit) ?
"p4 sync -f" will force all of the depot files to be downloaded to your client, but it won't remove files from your client that aren't in the depot. I would recommend using "p4 clean" instead (your server needs to be at version 2014.1 or higher -- if you're on an older server you can script an equivalent but it's a few extra steps).
I.e. do:
p4 sync ...
p4 clean ...
to make sure you have an up to date clean copy of everything in the current directory.

Download file from perforce depot without a client workspace?

Is there a way to download a file from a perforce depot without using a client workspace? I know about:
p4 print -o local.file //perforce_depot/remote.file
but this does only work if the requested file is under the clients workspace. I'm looking for something that is only dependent on the user and his rights but not on a workspace...
Thanks!
Your command will work without a client workspace, as long as the user has permission to access the file, and the file actually exists.
Run p4web on your perforce server, and then you can use wget to get any file.
I have my build servers wget their initial kickoff build scripts, that avoids the chicken/egg problem of you need something to kick a build, but you want that something to be in perforce. The only thing not in perforce now is a 2 lines. A wget, and an exec.

Integrated files disappear from a pending changelist at p4v

Our user performed an integration between branches.
Integrated files were placed in a pending changelist but they are invisible when I look
at this changelist in p4v.
I can see them when I look on this changelist when I connected to another workspace, I can also see then in Eclipse.
When I choose to Resolve conflicts on this changelist it works too, but
when I try to submit the changes, there is nothing there.
After I installed a new version of p4v, the problematic pending
changelist appeared with a question mark (red triangle with a question
mark).
Any Ideas?
Thanks.
Answer from Perforce support:
This may be a working and locks out of sync
issue. Can you run the following server command:
p4d -r $P4ROOT -xf 925
Where "$P4ROOT" is the location of the db.* files.
P4V.exe allows the user to specify a filter on his workspace. Perhaps the workspace had a filter applied, such that the GUI did not show the files, where the command line client and others (ie Eclipse) would not be privy to this filter and would show the files.
Another possibility is that the user was logged in under a workspace other than his default, and the files were checked out in his default workspace. It would be easy to then find these files in his default by looking at pending changelists for all users.

Resources