Igal
Igal

Reputation: 1114

Perforce client side pre-commit hook

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.

Upvotes: 12

Views: 7963

Answers (3)

chen bin
chen bin

Reputation: 568

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

Upvotes: 1

Tim P
Tim P

Reputation: 51

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.

Upvotes: 5

Bryan Pendleton
Bryan Pendleton

Reputation: 16359

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.

Upvotes: 5

Related Questions