SVN hooks usage demo

Source: Internet
Author: User

SVN provides the hooks script. The so-called hook is actually a time trigger mechanism that triggers our predefined actions when the system executes a special event, this allows us to do what we want when a specific State occurs.

Enter the code repository of a generated subversion, and there is a hooks directory under the directory to enter the directory. Normally, you should see:

. Tmpl is a template file for every hooks. It is actually a text file. After opening it with Vi, you can see the comments and detailed descriptions in it. These are the first-hand help files we can use.

For example, the svn server has nine types of hooks:

A. Two types of lock
A1.pre-Lock
A2.post-Lock
B. Two types of unlocking
B1.pre-Unlock
B2.post-Unlock
C. Three types of submission
C1.start-commit
C2.pre-commit
C3.post-commit

The order is C1 ----> C2 -----> C3

D. Two types of attributes
D1.pre-revprop-change
D2.post-revprop-change

For example, if we want to force SVN submitter to enter the corresponding log, we need the hooks pre-commit.

Pre-commit: When SVN receives the file submitted by the user, it will call pre-commit before it is finally saved to repository, and pass two parameters at the same time, one is the submitted repository path (the actual server path), and the other is txn-name. transaction name, which is used to identify the transaction ID of the commit process.

Rename the pre-commit.tmpl to pre-commit and grant the file executable permissions at the same time, otherwise, the error message of Alibaba Cloud is displayed after the script is executed: SVN: commit blocked by pre-commit hook (exit code 255) with no output .)

Modify the pre-commit file as follows:

#! /Bin/shrepos = "$1" txn = "$2" svnlook =/usr/bin/svnlook logmsg = '$ svnlook log-T "$ txn" "$ repos" | grep "[a-zA-Z0-9]" | WC-C' if ["$ logmsg"-lt 5 (required log length, )]; thenecho-e "nempty Log message not allowed. commit aborted! "1> & 2 exit 1fi # all checks passed, so allow the commit. Exit 0

You do not need to restart SVN. When submitting code, you must write comments as required.

TIPS:

1. After the configuration is complete, you must add executable permissions to the corresponding *-commit. Otherwise, an error will occur.

,

2. Exercise caution when using post-commit because the entire operation cannot guarantee atomicity.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.