how to move pending changelist file to default with command - command-line

I'm preparing python script for check the pending default is empty or not. if has I will put them all in a new pending change-list, after I done by other operation. I need put this pending change-list file back to default.
but I don't know how to put the specify change-list back to default.

To move a file (//depot/foo) from the default changelist to an (already created) numbered changelist (1234), use
p4 reopen -c 1234 //depot/foo
To move it from 1234 back into the default changelist, use
p4 reopen -c default //depot/foo

p4 -F %depotFile% opened -c CHANGE | p4 -x - reopen -c default
i.e. get all files opened in CHANGE, then reopen them in the default changelist.

you can use the following command to move a file from a known change list to the default.
p4 reopen -c default file_path
moving between changelists is described here.

Related

Use p4 shelve in perl script without opening the editor

I'm trying to shelve my changes via perl script. After running p4 shelve it opens up an editor where I need to enter the description, save and exit.
The problem I'm facing here is this script will be running on server side where we don't need user input so I need to handle this interactive mode to non-interactive so that I can shelve and proceed my next steps with shelved changelist. Are there any options ?
use P4;
my $client = $ENV{client};
my $p4 = P4->new();
$p4->Connect();
$p4->SetClient($client);
$p4->Run('shelve');
Use the -c flag to shelve an existing pending changelist rather than opening an editor to create a new numbered pending changelist. I haven't used P4Perl, but according to the doc you can create a new changelist by doing something like:
$change = $p4->FetchChange();
$change->{ 'Description' } = "Some description";
$p4->SaveChange($change) # get a $changenum from the output of this
so you should be able to do that and then shelve that changelist by doing:
$p4->Run('shelve', '-c', $changenum);

How to check if a file is already marked for add?

I'd like to check if a file is already locally marked for add, without adding the said file. Is this check possible with a Perforce command?
If you use the -n option it will preview the add operation telling you which files would be added but not actually adding the file.
Source
p4 add -n testfile
I personally use below two commands:
p4 diff -sa // to show list of all opened files
p4 diff -se // to show list of all files that are with changes but not opened
You can check if a file is marked for add by running the fstat command. If the command output contains the string "action add", that means the file is already marked for add.

Perforce: command line to list files marked for delete

I have files that are marked for delete in my workspace (but not yet submitted). Now I want them to be listed at command line. I have tried the following command without success.
p4 diff -sd "C:\myworkspace\..."
I could not find any option in the diff command to list files that are marked for delete. Is it another command, or a hidden option?
The command you are looking for is p4 opened
C:\Proj\test>p4 opened
//depot/Test/_header.txt#5 - delete default change (text)
//depot/Test/personnel_updates.sql#1 - add default change (text)
You would probably want to filter the output to only include the files as marked for delete (you can see I have an add and delete on the default changelist).
C:\Proj\test>p4 opened | findstr " - delete "
//depot/Test/_header.txt#5 - delete default change (text)
Note: You can also use the -c parameter to specify a certain changelist if you have placed your changes on a numbered changelist.
Or you could use fstat:
p4 fstat -Ro -F "action=delete" -T depotFile,clientFile //...

Delete a Perforce client workspace with pending files when the workspace has already been removed from disk?

How do I delete a workspace that has pending files when that workspace has already been removed from disk?
Caveats:
p4 command line only; not p4v gui
regular user access; no admin access
Scenario:
create a workspace named user_workspace on the disk in the ~/my_workspace directory
p4 edit files in workspace on the default pending changelist
remove workspace by hand (rm -rf ~/my_workspace)
workspace still exists on server with pending files
Solutions that don't work:
1: Delete workspace
Doesn't work because the workspace has files opened.
p4 client -d user_workspace
Client 'user_workspace' has files opened; use -f to force delete.
2: Delete workspace with force
Doesn't work because not admin.
p4 client -d -f user_workspace
You don't have permission for this operation.
3: Delete the pending changelist; then delete workspace (try 1)
p4 changes -c user_workspace -s pending
Only lists pending numbered changelists, does not handle the default pending changelist.
p4 -c user_workspace -d changelist_number
Not possible because there is no changelist number for the pending changelist.
4: Delete the pending changelist; then delete workspace (try 2)
Trying to do a p4 revert on a directory that does not exist anymore gives a strange error.
p4 revert ~/my_workspace
/home/user/my_workspace - must refer to client 'user_workspace'.
p4 -c user_workspace revert ~/my_workspace
/home/user/my_workspace - must refer to client 'user_workspace'.
setenv P4CLIENT user_workspace; p4 -c user_workspace revert ~/my_workspace
/home/user/my_workspace - must refer to client 'user_workspace'.
1. Revert the pending changelist
Have to use Perforce depot notation instead of local directory notation because the local directory does not exist anymore.
p4 -c user_workspace revert -k //...
//blah/blah/blah/file#rev - was edit, reverted
2. Delete the client workspace
p4 client -d user_workspace
Client user_workspace deleted.
this will give you the pending changes on the client
p4 changes -c user_workspace
this will delete the pending change list of your choice
p4 change -d <change list number>
after that, you can delete the client using
p4 client -d user_workspace
The command line did not work for me. It kept reporting "over license quota" for any commands. I probably have something configured wrong related to that. This would mean I would have to first correct that problem and then use the above solution. However, I found another way to fix this issue using the p4v client.
The junk workspaces were old workspaces from my previous computer. Those without any files checked out I was able to right-click delete in the workspaces tab view. Those workspaces with files left checked out I was not able to remove as other are experiencing. To removes these I had to take a few extra steps.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Alternatively: Try these four step using only the p4v client *
Edit the workspace and just blank out the host field of the old workspace. In another thread I read this allows editing from any computer.
Switch to the workspace
Revert the files in the WORKSPACE view; there was no need to sync the files to my local machine
Delete the workspace after switching back to the workspaces tab.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I hope this helps someone.
Wrote this script called p4-delete-client for deleting a p4 client (which has changelists & other problems).
It has the following features:
automatically deletes changelists (reverts pending & deletes shelved)
fixes hostname (if differs from the one the client was created on)
unlocks the client if locked
deletes the client
deletes associated files (can be configured not to from arguments)
Note that the script relies on other scripts in the repo.
The rm -rf command only deleted files on your system, the workspace still exists in perforce. If you want to delete it, you have to revert the files first.
p4 revert ~/my_workspace
p4 client -d user_workspace

What is the command line syntax to delete files in Perforce?

I am creating some build scripts that interact with Perforce and I would like to mark for delete a few files. What exactly is the P4 syntax using the command line?
p4 delete filename
(output of p4 help delete)
delete -- Open an existing file to delete it from the depot
p4 delete [ -c changelist# ] [ -n ] file ...
Opens a file that currently exists in the depot for deletion.
If the file is present on the client it is removed. If a pending
changelist number is given with the -c flag the opened file is
associated with that changelist, otherwise it is associated with
the 'default' pending changelist.
Files that are deleted generally do not appear on the have list.
The -n flag displays what would be opened for delete without actually
changing any files or metadata.
Teach a man to fish:
p4 help - gets you general command
syntax
p4 help commands - lists the
commands
p4 help <command name> -
provides detailed help for a specific
command
http://www.perforce.com/perforce/doc.062/manuals/boilerplates/quickstart.html
Deleting files
To delete files from both the Perforce server and your workspace, issue the p4 delete command. For example:
p4 delete demo.txt readme.txt
The specified files are removed from your workspace and marked for deletion from the server. If you decide you don't want to delete the files after all, issue the p4 revert command. When you revert files opened for delete, Perforce restores them to your workspace.
Admitted - it takes a (small) number of steps to find the (excellent!) Perforce user guide online in the version that matches your installation and get to the chapter with the information you need.
Whenever I find myself in need of anything about the p4 command line client, I rely on the help Perforce have built into it. Accessing it could not be easier:
on the command line, enter p4
This gets you to the information Michael Burr has shown in his answer (and some more).
If you do not get a help screen right away, something is wrong with our client configuration, e.g. P4PORT is not set properly. You obviously need to fix that first.