Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Any idea?

Thanks!

like image 472
AJ Gottes Avatar asked Jun 14 '15 13:06

AJ Gottes


People also ask

What is Perforce client workspace?

A Perforce client workspace is a set of files on a user's machine that mirror a subset of the files in the depot. More precisely, it is a named mapping of depot files to workspace files.

What does p4 change do?

p4 change brings up a form for editing or viewing in the editor defined by the environment variable P4EDITOR . When no arguments are provided, this command creates a numbered changelist. All files open in the default changelist are moved to the numbered changelist.

What is unload workspace?

Load the contents of a repository workspace into a local Eclipse workspace so that you can work with project contents. Unload the workspace when you no longer need local copies of the projects it contains.


1 Answers

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.

like image 74
Bryan Pendleton Avatar answered Oct 20 '22 09:10

Bryan Pendleton