Perforce client side pre-commit hook

会有一股神秘感。 提交于 2019-12-22 05:33:39

问题


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.


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/16053503/perforce-client-side-pre-commit-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!