Creating a label from template label in Perforce - perforce

I'm trying to create a new label by using the p4 commands line, as in, go from template label my_label_template to my_label_1, but I can only find below commands which works create new label from template, but it doesn't seems to have option to input the Revision.
p4 label -o -t my_label_template my_label_1
Is there any way to create new label by using the p4 commands that also included input revision?
Thanks

Make sure you have a current version of the p4 CLI binary (2016.1 or newer).
Then use the --field global opt to add in the Revision field:
p4 --field Revision=#whatever label -o -t my_label_template my_label_1 | p4 label -i
https://www.perforce.com/blog/vcs/20161-command-line-roundup

Related

How to change description of a pending (shelved) changelist using command?

I've created CL#100 with some description and shelved some files.
Now I need to edit the description of that CL using a command.
I have tried these 2 ways and both failed (same error msg)
p4 change -u 100 "Description: test description edit"
p4 change -o 100 > myDes.txt >> Edit Description field in myDes.txt >> p4 change -u 100 < myDes.txt
Error:
Execution Failed: "'C:
Program" "C:\Users\iman\AppData\Local\Temp\t26660t63.tmp": The system cannot find the file specified.
Client side operation(s) failed. Command aborted.
Edited File C:\Users\iman\AppData\Local\Temp\t26660t63.tmp kept due to errors.
It sounds like your P4EDITOR is set to "C:\Program", which is making p4 unable to launch an editor. This will cause problems for any command which edits a spec, not just p4 change commands! Do:
p4 set P4EDITOR=notepad
to set your editor to notepad (the default on Windows).
Then you should be able to run:
p4 change 100
The -u flag isn't needed for the update since this is a pending changelist (you can freely edit your pending changelists by default). The description is not specified on the command line; it's part of the spec that you'll edit in the editor.
If for some reason you need to do this without an editor (e.g. you're writing a script), you need to use -o to output to stdout and -i to input from stdin. I recommend using --field to modify the field instead of writing your own script to parse the changelist spec:
p4 --field "Description=test description edit" change -o 100 | p4 change -i

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

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.

Is there a single Perforce command to display a list of all the check-ins to a file/dir along with the list of files that changed and the description?

p4 changes -l ... shows us the list of check-ins and the description, but it doesn't show the list of files that were modified in the check-in. Is there a way to do that in one command, without the need to create a wrapper script that combines the output of another command like p4 describe or p4 file?
In Subversion, I can do this by running svn log -v.
The 'files' command can do what you're looking for. An easy way is:
p4 files //...#=<changelist>
That example will list the files modified by that changelist, under the view specified.
You can use the "describe" command to get the description of a changelist, along with the files affected.
For example, p4 describe -s <changelist> will describe the changelist, and the "-s" will prevent it from displaying file diffs.
One liner, list all changes made to a branch, with description and list of affected files, without showing the diff. Thanks to a combination of answers. Works on windows with Unix utils
p4 changes -s submitted //depot/xxx/yyy/zzz/... | grep -o "^Change [0-9]*" | cut -f2 -d" " | p4 -x- describe -s
Output:
Change 1753385 by user#clientspec on 2019/03/08 06:29:44
Changing the world
Affected files ...
... //depot/xx/yy/zz.h#6 edit
Change 1751752 by name#clientspec on 2019/03/05 15:24:00
I made a change to a file
Affected files ...
... //depot/xx/yy/zz.h#3 integrate

How can I change the description of a existing changelist in command line?

The command "p4 change" prompts a editor and needs a form. But I want to do this in command line.
How can I achieve this?
Use the following command:
p4 change -u CL_number
For details, please visit this page.
This command line worked for me:
p4 --field Description="New CL description here" change -o *changelist_number* | p4 change -i
There's always the -i command:
Read a changelist description from standard input. Input must be in the same format used by the p4 change form.
As Bryan points out in his comment the best approach is probably to run change -o, redirect the output to a file, process the file with other shell commands, and then send that file back to the server with change -i.
Source
But you can always change the description when you submit:
p4 submit -d "description"
This only works on the default change list.
Source

Resources