We are using perforce as a source control for Visual studio solution. Working with P4 and P4V. Is it possible to add client side pre-commit hook? for instance to ensure the word "debugger;" is not exist in *.js files. Could find something in Google. Thanks.
3 Answers
Perforce triggers can be used to enforce such a policy, but they run in the server, not client-side. So most sites that I'm aware of would enforce a rule such as the one you describe using a change-content trigger in the server.
http://www.perforce.com/perforce/doc.current/manuals/cmdref/triggers.html
It's not obvious from your question why you need to have a client-side hook. Is there some reason you don't want to use a change-content trigger?
Perhaps you might consider re-framing your workflow as a code review process, and implement policies like this in your code review tool of choice.

- 16,128
- 3
- 32
- 56
-
Thanks, the reason that I want it on client side is that I don;t want it to be pre commit hook on all developers but on specific group. – Igal Apr 29 '13 at 10:16
-
3It would be easy enough to implement a server-side trigger which implements on a pre-commit hook only for specific users, since the user name is available with the changelist information. My reason for wanting to implement a client-side pre-commit hook is different though, I want to have the ability to run checks on information that only the user's machine knows. For example, a pre-commit check to ensure that the user tested the executable before checking in, or a pre-commit check that scans for files which are involved in the build but haven't been added to a changelist. – uglycoyote Dec 18 '15 at 18:32
-
we have similar type of requirement. Any way to invoke make file before perforce submit on CLIENT – druveen Mar 29 '18 at 08:59
One approach that you could use is a "Custom Tool": https://www.perforce.com/perforce/doc.current/manuals/p4v/custom_tools.html
Basically you would write a script that takes the changelist as an arg checks your condition on every file in your changelist and calls p4 commit if it succeeds.

- 41
- 1
Use latest git-p4
. My patch for the hook p4-pre-submit
is merged into Git's next
branch.
The hook is a simple executable script which will stop the submit process to start up if the script exist with non-zero status. So p4-pre-submit
hook is pretty safe without any side effect.
See https://github.com/git/git/blob/next/Documentation/git-p4.txt for details.
Please note git-p4
is an independent python script. It's not dependent on any specific version of git. So you can upgrade git-p4
only.
The hook p4-pre-submit
has no other interaction with git/git-p4
except exiting status. So you can write the hook in any language (I recommend python).
Here is sample .git/hooks/p4-pre-submit
:
#!/bin/sh
cd $GIT_DIR && make test

- 568
- 4
- 16