Is there an easy way to reset P4 Client View (Command-line)? - perforce

I would like to make bash-script which resets the workspace completely (Removes files and client view). But so far I haven't found any command which removes all the mappins in the client view - without having to manually delete the mappings from the file. Anyone know how to do this?

I'm not sure if you're allowed to save a blank client view, but here's how you'd do it:
p4 --field View= client -o | p4 client -i
From your description it sounds like you might want to actually just delete the client spec? E.g.:
p4 revert //...
p4 sync #none
p4 client -d CLIENTNAME

p4 client -o | grep -v '//depot' | p4 client -i

Related

List all the changes with contents from a specific user

I am trying to get the changes with diff from the changes from a specific user. once I know the change I can get the details using "p4 describe".
Do we have a way to get list of all the changes with contents from a specific user?
Use the p4 changes -u USER command to get the list of changes, then run "p4 describe" on each.
p4 -Ztag -F "describe %change%" changes -u USER | p4 -x - run

How to 'move' directories on Perforce/P4V without sync to local

I am trying to move a crazy amount of files on perforce.
It was almost done on my first attempt using p4 integ -v
However, the integ command 'copies' the selected files.
I have to delete the source files and leave only target files for some reason.
Next, I tried p4 move command. This command has no -v option with it.
It is also impossible to sync all files to my local machine. (tens of TB)
Does anyone know how to perform p4 move without actually sync it?
Now, I've tried -k option to fake perforce out:
p4 sync -k //src_dir/...
p4 edit //src_dir/...
p4 move -k //src_dir/... //tar_dir/...
But Perforce reports submit failed because I don't have //tar_dir in my local machine. Did I missed anything?
Unless you specifically require the "p4 move" semantics (e.g. maintaining atomicity of each add/delete pair when integrating to other branches -- and since it sounds like you're doing this on an entire branch or even multiple branches I'm guessing you DON'T want that), I'd recommend doing:
p4 copy -v //src_dir/... //tar_dir/...
p4 sync -k //src_dir/...
p4 delete -k //src_dir/...
p4 submit

Perforce: How can I delete a changelist that p4v refuses to delete?

After a while of working with perforce I was left with a lot of still open change lists.
To clean up I want to get rid of a subset of them.
So here is what makes this complicate:
For a subset of the changes the host of the client has changed.
Some changes contain shelved files.
Files from the change list may be deleted or moved.
When one or more of above points are true for a change list, p4v (the visual client) will not allow you to delete the change list.
So what is an effective way of deleting these change lists?
First of all, perforce refuses to work on any change lists if the host differs in their workspace. So step one is to change the host of the workspace to the current one. This can easily be done with the visual client p4v. Open the properties of a workspace, choose edit and change the host.
Then you can use the command line to get rid of the pesky change list(s):
# to delete a changelist
CLIENT="name_of_your_client"
CHANGE="number_of_the_changelist_to_delete"
p4 -c $CLIENT shelve -c $CHANGE -d //... # Delete all shelved files from it.
p4 -c $CLIENT revert -k -c $CHANGE //... # Revert all files from changelist (only metadata).
p4 -c $CLIENT change -d $CHANGE # Finally delete the changelist.
After the last command the change list will be gone forever.
Fixing the hostname can be done from the command line like this:
client_hostname="$(p4 client -o ${CLIENT} | grep "^Host" | awk '{print $2}')"
p4 client -o ${CLIENT} | sed "/^Host:/ s=${client_hostname}=${HOSTNAME}=" | p4 client -i
Had the same problem some time ago and wrote a script (p4-delete-changelist) that overcomes all of these problems (and another one - deleting p4 fixes).
Note that the script depends on another file in the repository.

How do I get the perforce root directory from command line?

How do I get the perforce root directory from the command line? I've tried p4 info but I'd rather not have to filter this to get at the root. I'm sure there's a way, but I couldn't find it.
Is there a way to get the root in a context sensitive way? For example if I have two workspaces with a hierarchy like A/.../script vs B/.../script I'd expect that the script would return either A or B depending on where it was run from.
If you want your client root in one command run:
p4 -F %clientRoot% -ztag info
You will need the 2014.1 later version of p4 to use this flag.
For older versions before 2014.1 use the command
p4 info | grep 'Client root:' | cut -d ' ' -f 3-
From OP’s description, they probably want p4 where. For example, if the client root is /perforce/projects, then
p4 where //depot/project-1/module-2
will give /perforce/projects/project-1/module-2. Credit from Bryan’s comment.

Changing workspace clobber option directly from Perforce command line

How to change perforce specs from command line?
What I want to do is, I have a workspace whose clobber option is set to noclobber (default value). Now I want to change it to clobber.
I know I can do it directly from p4v, but I don't want that. I also know that if I run p4 client, it will open P4CONFIG file in text editor, where I can change noclobber to clobber and save the file and it's done, but I also don't want that.
Please tell me the specific command which directly changes noclobber to clobber without using p4v or without editing P4CONFIG.
If you're trying to avoid repeatedly opening a text editor, you can accomplish your goal with a little bit of sed, like this:
p4 client -o | \
sed 's/ noclobber/ clobber/' | \
p4 client -i
It's pretty easy to script this with Perl, Python, Ruby, or even Powershell. Here's a one-liner in Powershell:
p4 client -o | %{$_ -replace "noclobber", "clobber"} | p4 client -i
Simplest solution:
P4EDITOR='sed -i s/noclobber/clobber/' p4 client

Resources