Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN Pre-commit hook to be triggered for a particular folder

One of our client's SVN repository has quite a bunch of projects under the single repository. Now I want to check coding-standard for one of the project via pre-commit hook.

If I configure the pre-commit, it is going to affect all the projects (folders) in the repository, how do I tell the hook-script to trigger (check the coding standard) only when a file from a particular folder (or project) is committed.

UPDATE

The coding standard is intentional for Zend and I am going to use PHPCS (PHP Coding Standard) to validate the coding-standard.

like image 485
Rakesh Sankar Avatar asked Aug 16 '11 06:08

Rakesh Sankar


People also ask

How to run precommit hooks?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow.

What is a pre-commit hook?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.

What are svn hooks?

A hook script is a program triggered by some repository event, such as the creation of a new revision or the modification of an unversioned property. Each hook is handed enough information to tell what that event is, what target(s) it's operating on, and the username of the person who triggered the event.


2 Answers

Use svnlook in the pre-commit to see the paths changed, and if the path contains the project you are considering, do the coding standards etc.

You can use the dirs-changed subcommand (and the --transaction flag):

http://svnbook.red-bean.com/en/1.5/svn.ref.svnlook.c.dirs-changed.html

Or the changed subcommand:

http://svnbook.red-bean.com/en/1.5/svn.ref.svnlook.c.changed.html

Example of a pre-commit using svnlook: http://wordaligned.org/articles/a-subversion-pre-commit-hook

like image 95
manojlds Avatar answered Oct 11 '22 03:10

manojlds


You cannot. The script needs to check all the affected paths (they can be more than one) and act accordingly.

like image 20
Álvaro González Avatar answered Oct 11 '22 03:10

Álvaro González