perforce workspace command line - perforce

I'm trying to understand how perorce work and I'm struggling with command line
I have a single depot with 3 project inside
so depot:
projectA
projectB
now I have 2 workspaces, one mapped only on projectA and one on projectB.
Here I have my trouble , using interface everything works
but with command line I have not enough knoledge on perforce.
I use
p4 -c workspacA //to switch workspace
then I run: p4 cstat
and it give me all the information about changelist contained in all depot
not only depot/projectA
But I woul like to enter in a workspace and run my command only on that workspace
Is this normal? I see that I need to specify my depot mapping but this seems strange to me.
Can someone clarify me this?
Thanks

Do:
p4 set P4CLIENT=workspaceA
If you use -c workspaceA it applies only to that one command, whereas p4 set is persistent.
I also recommend looking at documentation on P4CONFIG, which lets you associate Perforce config settings with local directories (so you switch workspaces automatically when you cd to a different workspace root).
https://www.perforce.com/manuals/v16.2/cmdref/P4CONFIG.html

Related

How to find the local perforce depot path?

I am trying to write a maven compile command and want it to work on my colleagues' machines as well, and since they have a different perforce depot path than mine, I need a unified way to find it.
I have tried p4 where but it didn't help.
When you run the p4 where command make sure that you're using the correct client workspace.
E.g.:
p4 set P4CLIENT=my_client_name
p4 where //depot/...
or:
p4 -c my_client_name where //depot/...
The example you describe of p4 where returning the wrong path indicates that it's giving the answer in terms of a different client workspace.

automatic selection of workspace when launching p4v

In the shell, when I am in a directory located as part of a p4 workspace, I can run p4 commands in the shell and it knows what workspace I am in.
However, when I launch p4v, I have to manually find the workspace that I want to load. Since, the context of p4 commands to run is already known in the shell, how I can I pass that to p4v, so it will launch in the same workspace. There's no reason why I should have to select a workspace when I launch the tool, since the p4 toolchain already can self-determine the context.
I should only have to select the workspace if I am wanting to select some other workspace that I am not currently operating under.
As you've found, P4V has its own settings file and ignores the shell's environment. Per this blog post:
https://www.perforce.com/blog/100114/p4v-secrets-calling-p4v-command-line
the way I'd handle this would be to write a script/alias that wraps P4V and passes the current environment to it. Something along these lines:
$_ = `p4 -Ztag -F "%serverAddress%#%clientName%#%userName%" info`;
#env = split /\#/;
exec "p4v -p $env[0] -c $env[1] -u $env[2]";

perforce command to know the non versioned files

I am new to perforce. i have client created in linux.
and synced all the files from the repository. previously we were using svn to add and delete files to a repository.
in svn we have a command to know the status of the tree by "svn st" which shows all the local modifications(with symbol M) and also the non versioned files(with symbol ?).
i want to know what is the equivalnet command for this in perforce which shows all the non versioned files also.
Could anyone please help me with th command in linux.
In Perforce changes that have been "opened" (using P4 terminology) are attached to changelists. To list the changelists use the changes command:
p4 changes
To see the changes attached to a specific changelist use the change command:
p4 change -o $CHANGELIST
The status command without any options will preview files that are added, deleted or modified but that haven't been opened (which really means haven't been attached to a changelist).
p4 status
The status command or the reconcile command can also be used to "open" the changes. Note that the status command will of course exclude files you have ignored. If you want to see them use the -I option.

I've deleted all the files in my directory. How can I get them back?

I'm new to Perforce and, to be honest, I'm hating it.
I had about 20 files in my c:\workspaces\perforce directory and I selected all of them and hit the delete key.
They were all checked in before I deleted them.
I've been pulling my hair out trying to figure out how to get them back (Perforce is sooooo unintuitive) but there's nothing that stands out to a n00b like me to.
How can I get the latest revisions back into the directory from Perforce?
You need to do a force sync.
On the command line:
$> p4 sync -f
In the P4V GUI:
Right-click on the directory to update
Select 'Get Revision'
In the dialog, check 'Force operation'
Click 'Get Revision'
The perforce server keeps track of which files you pulled in last time. This is done so that, the next sync only brings in the files which have changes since the last sync, instead of all the files once again.
To override this behavior, you need to use the -f option.
The -f flag forces resynchronization even if the client already has
the file, and overwriting any writable files. This flag doesn't
affect open files.
If you're using the command line client, you can run this command from the directory where you want to sync up:
p4 sync -f ...
You might also want to check the list of opened files, since sync -f will not be bringing in changes corresponding to those files (even if you have deleted them).
This command should list all the opened files:
p4 opened ...
If you have any files listed in the above list, which you had deleted as well, you should revert them before running sync -f.
p4 revert <FILE1> <FILE2>
p4 sync -f ...
If you're using p4v, you could follow the steps mentioned by dwinkle:
1. Right click the folder in your workspace
2. Choose `Get Revision` in the context menu.
3. Choose `Get Latest revision`
4. Check `Force Operation (replace file even if you already have the revision specified)
5. Click on `Get Revision` button to fetch the files.
To look at the list of opened files using p4v, you would have to look at your list of pending changelists. You should be looking in the default changelist, if you have not put the files in any speficic changelist. Right click on files that you see there that you had deleted earlier, and choose Revert.
if you have files checked out, and then deleted. You need to revert(p4 revert -a //...) the folder before you get latest forced (p4 sync -f).
An alternative:
p4 reconcile
p4 revert //...
If you don't care about the old client, one solution would be to pull down a new client:
p4 newclient
p4 sync
If you want the client to have the same name, you can do a forced sync as others have mentioned:
p4 sync -f
If you want the client to have the same name, but your directory is no longer recognized as a p4 workspace, you will need to delete the client and then recreate it.
p4 -c <client_name> client -d <client_name>
p4 newclient
Right click on parent directory.
Click "Reconcile" in context menu.
Let a new change list be created.
Right click changelist.
Revert change.
In my case I tried everything and I couldn't get all of my files to revert, so I tried deleting them and then I couldn't get all of them back. I restarted my pc, and tried numerous solutions found online. In the end my problem was solved by one or all of the following: upgrading to the latest P4V application, running the application with elevated permissions, and going to lunch after forcing get latest.
If you wasted half of a day. You may want to try the above.
I've deleted all the files in my directory. How can I get them back?
One wrinkle to this that I just stumbled over is that if you remove the directory you can't just use p4 sync -f to get it back. I wanted a complete clean version of the directory so I did a:
rm -rf directory1
However when I did a p4 sync -f directory1 on it, it spits out:
directory1 - no such file(s).
What I found that works is to recover a file inside of the directory first:
p4 sync -f directory1/some-file
You will have to know the name of one of the files inside of the missing directory which you can get using:
p4 files //depot/some/path/directory1/\*
Once you get one of the filenames, do:
p4 sync -f directory1/some-file
This should create the directory1 directory. Then you can do a full sync inside of the created directory:
cd directory1
p4 sync -f ...
Hope this helps someone else.

P4 - change workspace for client

I want to change the workspace client using the p4 command line but i don't know if its possible.
You can create, delete or edit workspace using the p4 workspace command, but i want to change the current workspace with a .bat method.
Exemple :
p4 -c MyClient changeworkspace myNewWorkspace
If you know in first step if it's possible.
Thanks.
Either set the P4CLIENT environment variable to the name of the workspace you want to be your current workspace, or consistently pass that workspace name as the value of the -c flag on your p4 commands: http://www.perforce.com/perforce/doc.current/manuals/cmdref/env.P4CLIENT.html#1040647
See also these other ways to set the environment variable (many people find P4CONFIG files helpful): http://www.perforce.com/perforce/doc.current/manuals/p4guide/02_config.html#1069873

Resources