What is the p4 command equivalent to something like git/hg/bzr/svn status? (Hint: not `p4 status`)
Hint: it is NOT
p4 status. First,
p4 status is not a read-only status command, but actually changes the state of the workspace – it actually adds local changes to a pending changelist. Second,
p4 status does not tell you about files that are on pending changelists.
It looks like some combination of
p4 status and
p4 opened is needed to get the bare minimum of what the other VCSes do in a single command.
Most version control systems have a command that can quickly tell you the status of a workspace. Information such as:
- what files are checked out for editing (if the VCS uses checkouts)
- which of those checked out files have been locally changed or deleted
- which files have been changed even though NOT checked out
- e.g. which files may have changes that you want to merge
- possibly which files are more recently updated in the repository than in your workspace
- e.g. changes that you may want to merge into your workspace
- what files are in the workspace but are not (yet) under version control
- e.g. which files you may want to add to the version control system
- or possibly add to your .hgignore/.gitignore/… ignore file patterns
- what files are under version control but are not in the workspace
- e.g. which files you may want to delete from your version control system
- or which files you may have accidentally deleted
Exactly what status information is provided depends on the VCS. E.g. Perforce is checkout based, but most modern version control tools are not.
But… nearly all version control tools have a single, simple, command that will tell you such status.
Except, apparently, perforce.
… I may go on to provide examples of what git/hg/bzr/svn status do in a single command, but which perforce seems to require at least two commands to provide.
One Solution collect form web for “What is the p4 command equivalent to something like git/hg/bzr/svn status? (Hint: not `p4 status`)”
I keep saying that I dislike answering my own question, but I am going to do this here. I welcome anyone who wants to share better solutions and scripts. I would especially welcome somebody showing me that this is unnecessary, that Perforce actually does have the equivalent of
git/hg/bzr/svn status =
p4 opened +
p4 reconcile -n
In perforce at least two separate commands seem to be required to approximate what other VCS tools do with a single command, to provide a quick summary of the status of the workspace wrt the depot:
p4 opened – for a list of files that you have opened in the workspace
p4 reconcile -n – for a list of files that are not opened wrt perforce, but to which you have made local changes.
p4 reconcile -n to say “make no changes.)
—+ Suitable for an alias or quick typing
I combine these as follows:
p4 $P4OPTS opened p4 $P4OPTS reconcile -n | sed -e 's/ - / - RECONCILE TO MAKE: /'
The sed part to better differentiate the status for files that perforce already has opened from the status of files not opened under perforce. But I note that this is unsafe, when a file may have the string ” – ” in its name.
Because I often want the local paths, I currently use the following shell script
my-p4-status to give me something more like what I am used to from other VCSes’ status command:
#!/bin/bash # Perforce lacks a single command to tell you the status of a workspace, # the equivalent of hg/bzr/git status. # Warning: "p4 status" is not actually a read-only query!!! # "p4 status" is more like "p4 reconcile" - it actually opens files to edit, add, or delete (-e -a -d) # p4 opened only reports on the status of files currently opened by Perforce # It is necessary to combine "p4 opened" and "p4 reconcile -n" to get a net overview. # TBD: convert to local file path, rather than depot path. # (Not a simple sed-xargs-p4_fstat pipeline) P4OPTS='' if [ "$1" == "-ztag" ] || [ "$1" == "-verbose" ] then shift P4OPTS="-ztag" fi case $P4OPTS in -ztag) p4 $P4OPTS opened p4 $P4OPTS reconcile -n ;; *) echo '#### p4 opened - Perforce files already opened ###' p4 $P4OPTS opened echo '#### p4 reconcile -n --- local edits, not opened in Perforce. Run p4 reconcile to actually open. ###' p4 $P4OPTS reconcile -n | sed -e 's/ - / - RECONCILE TO MAKE: /' esac
—+ Better? Please Share!
If you have anything better, please share.