abergmeier
abergmeier

Reputation: 14071

Getting Perforce client workspace handling automated

I am trying to automate access to Perforce via it's command line utility. Creating a new client workspace with p4 client and syncing works ok.

Now I am allowing users to overwrite user, host, port, stream, revision. From the docs it is not clear to me when I have to execute which commands to get the client workspace files in sync with an edited client workspace spec.

What I currently do is once p4 client is through search for

Client mymachine not changed

in stdout and do a p4 sync -f should the message not appear.

Is there a better or more sane way to do this?

I tried executing e.g. p4 sync -s in hope that it would fail should local data be deleted but it seems that I misunderstood the option?

Upvotes: 0

Views: 395

Answers (1)

Samwise
Samwise

Reputation: 71562

It is not clear to me how this relates to your question about workspaces:

Now I am allowing users to overwrite user, host, port, stream, revision.

since only one of those is a property of a workspace. I'm going to disregard that statement for now but if it was significant I'd encourage you to post a follow-up clarifying what you mean by "overwriting" each of these properties.

To your question:

From the docs it is not clear to me when I have to execute which commands to get the client workspace files in sync with an edited client workspace spec.

If the client View is updated, all you need to do is:

p4 sync

If the client Root is updated, or any of the other options that globally affect how files are written to the workspace, such as allwrite or modtime, you will need to re-sync the entire client. Ideally this is done by doing:

p4 sync #none

prior to changing the workspace in one of these ways. The other option would be to do something like the following sequence:

p4 sync #none
p4 sync
p4 clean

to make sure that everything is rewritten, and that any stragglers (e.g. anything that the "sync #none" couldn't locate because the Root had changed but that are still mapped in the client view) are removed from the workspace.

I tried executing e.g. p4 sync -s in hope that it would fail should local data be deleted but it seems that I misunderstood the option?

Deleting local data is a separate issue from editing the client spec, but for that the command you want is p4 clean rather than p4 sync -- you use sync to tell the server you want it to send you new revisions, you use clean to bring your workspace back in line with what the server already sent you.

The recommended/supported workflow is to always use p4 commands to manipulate the read-only files in your workspace -- so if you want to delete a local file, use either p4 sync FILE#none (to remove it from your workspace but not affect the depot) or p4 delete FILE (to open it for delete so that it will be deleted for everyone when you submit).

Upvotes: 1

Related Questions