6

I'm trying to discover how to change the default set of Client Spec options and submit-options.

set P4CLIENT=my_new_client_1
p4 client

Gives me the following spec default-spec:

Client: my_new_client_1
...
Options:    noallwrite noclobber nocompress unlocked nomodtime normdir

SubmitOptions:  submitunchanged
...

Now on my machine i want to always use revertunchanged, rmdir for example, but it seems like I need remember to manually set this everytime I create a new client.

Is there any way to achieve this? p4 set seems to only affect the things that can be set by environment variables.

Greg
  • 2,549
  • 2
  • 24
  • 30

3 Answers3

7

You can't change the default client spec template (unless you're the Perforce system administrator) but you can set up and use your own template. You would first create a dummy client with a client spec that has the values that you want:

Client: my_template_client
...
Options:    noallwrite noclobber nocompress unlocked nomodtime rmdir

SubmitOptions:  revertunchanged
...

Then you just specify that the dummy client should be used as a template when creating new clients:

p4 client -t my_template_client my_new_client_1
rettops
  • 611
  • 4
  • 10
  • Thanks, I suspected I'd have to resort to templates. I'm assuming your command line above is missing the "client" from the end ;) – Greg Jul 09 '10 at 07:10
  • Oops, sorry. That should have been 'p4 client -t my_template_client my_new_client_1' – rettops Jul 09 '10 at 07:39
3

The first response here was incorrect:

You CAN create a default clientspec in Perforce using triggers.

Essentially, you create a script that runs on the server and runs whenever someone does a form-out on the form client. This script would have to check to see if the clientspec already exists, and then substitute a sensible "default" if it doesn't (if it's a new clientspec).

Note that this works fine and well, and it's even in the P4 SysAdmin Guide (the exact example you're looking for is there!) but it can be a bit difficult to debug, as triggers run on the SERVER, not on the client!

Manual: http://www.perforce.com/perforce/r10.1/manuals/p4sag/06_scripting.html

Specific Case Example: http://www.perforce.com/perforce/r10.1/manuals/p4sag/06_scripting.html#1057213

Dana Lacoste
  • 179
  • 1
  • 7
  • 2
    Note that my first line said "unless you're the Perforce system administrator". Your examples are from the Perforce System Administrator's Guide. Triggers may only be defined by Perforce superusers. – rettops Jul 09 '10 at 22:57
  • 1
    Thanks for the info - I'm probably not going to have permission to set triggers, but I'll give that a go. I think what you have put is here is valuable to some, so maybe I could split this into two questions - one for strictly basic user and one for those with more complete access. – Greg Jul 10 '10 at 10:35
  • That "Manual" page has moved to https://www.perforce.com/manuals/p4sag/Content/P4SAG/scripting.triggers.forms.out.html (I think). – Philippe Chaintreuil Apr 11 '22 at 15:08
1

The Perforce Server Deployment Package (SDP), a reference implementation with best practices for operating a Perforce Helix Core server, includes sample triggers for exactly this purpose. See:

Using the p4 client -t <template_client> is useful and is something a regular user can do, and has a P4V (graphical user interface) equivalent as well. Only Perforce super users can mess with triggers.

There is one other trick for a super user to be aware of: They can designate a client spec to be used as a default if the user doesn't specify one with -t <template_client>. That can be done by setting the configurable template.client. See: https://www.perforce.com/manuals/cmdref/Content/CmdRef/configurables.configurables.html#template.client

One other suggestion: I suggest changing the default from submitunchanged to leaveunchanged rather than revertunchanged (as in the sample triggers above). Using leaveunchanged is better because, if you still want the file checked out, using leaveunchanged rather than revertunchanged saves you from having to navigate to the file to check it out again. It's a small thing, but optimal to go with leaveunchanged. If you do want to revert the unmodified file, it's slightly easier to revert than to checkout again, which might require more navigating or typing.

Tom Tyler
  • 11
  • 1