SVN hook Application

Source: Internet
Author: User

I. Introduction to the SVN hook script

The specific wording of the hook script is the operating system shell script program, according to their own SVN operating system and shell program for the corresponding development.


A hook script is a program that is triggered by some repository events, such as creating a new version or modifying a property that is not versioned. Each hook can have enough information to understand what happened, what the object was, and the account of the user who triggered the event. Depending on the output or return status of the hook, the hook program can control the action in some way to continue, stop, or hang.


Introduction to SVN's hooks template feature

Start-commit triggering a transaction before committing

Pre-commit Trigger transaction before commit completes

Post-commit Trigger transaction when commit is complete

Pre-revprop-change triggers a transaction before the Version property is modified

Post-revprop-change The transaction is triggered after the version property is modified


Post-commit

After the commit is completed, the hook is executed after the version is successfully created, the commit is completed and cannot be changed, so the script return value is ignored


Post-lock

Execute the script after the file is locked


Post-revprop-change

After modifying the revision property, execute the script. Because the revision has been completed and cannot be changed, the return value of this script is ignored by the rice

(However, the actual implementation seems to be that the correct execution of the script affects the property modification)


Post-unlock

Execute the script after unlocking the file


Pre-commit

After subversion transaction is complete, execute the script before committing


Pre-revprop-change

Execute the script before modifying the revision property


Start-commit

Executes the script before the client has yet to submit data to the server, that is, before the Subversion Transaction (abbreviated TXN) has been established


By default, the sub-directory of hooks contains various repository hook templates

[Email protected] ~]# ls-l/application/svndata/sadoc/hooks/

Total Dosage 36

-rw-r--r--1 root root 1977 June 16:42 Post-commit.tmpl

-rw-r--r--1 root root 1638 June 16:42 Post-lock.tmpl

-rw-r--r--1 root root 2289 June 16:42 Post-revprop-change.tmpl

-rw-r--r--1 root root 1567 June 16:42 Post-unlock.tmpl

-rw-r--r--1 root root 3426 June 16:42 Pre-commit.tmpl

-rw-r--r--1 root root 2410 June 16:42 Pre-lock.tmpl

-rw-r--r--1 root root 2786 June 16:42 Pre-revprop-change.tmpl

-rw-r--r--1 root root 2100 June 16:42 Pre-unlock.tmpl

-rw-r--r--1 root root 2780 June 16:42 Start-commit.tmpl


[email protected] hooks]# CP Post-commit.tmpl Post-commit

[Email protected] hooks]# vim Post-commit

Repos= "$"

rev= "$"


mailer.py commit "$REPOS" "$REV"/path/to/mailer.conf

touch/tmp/$ (date +%ms). log



[Email protected] hooks]# chmod 755 post-commit


Second, under the client

In D:\oldboy\trunk\test\tom.txt

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/8D/wKiom1V_lRygEWoKAAD5op7ripE781.jpg "title=" 10.png "alt=" Wkiom1v_lrygewokaad5op7ripe781.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/89/wKioL1V_lwDQ6eLQAAET-sx22pg490.jpg "title=" 11.png "alt=" Wkiol1v_lwdq6elqaaet-sx22pg490.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/8D/wKiom1V_lWXiXW62AAKXuB9Wx8g677.jpg "title=" 12.png "alt=" Wkiom1v_lwxixw62aakxub9wx8g677.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/89/wKioL1V_lyfxnifSAAIAa8d6RT4194.jpg "title=" 13.png "alt=" Wkiol1v_lyfxnifsaaiaa8d6rt4194.jpg "/>

Four, in return to the SVN server

Commit completed, trigger program, more log files in/tmp

[Email protected] hooks]# ll-lrt/tmp

Total dosage 16

DRWX------. 2 root root 16384 April 17:56 lost+found

-rw-r--r--1 root root 0 June 11:04 04S.log

-rw-r--r--1 root root 0 June 11:04 0452.log

-rw-r--r--1 root root 0 June 11:06 0644.log

-rw-r--r--1 root root 0 June 11:12 1224.log

-rw-r--r--1 root root 0 June 11:15 1548.log



Five, Hook script post-commit



Repos= "$"

Txn= "$"

#此处更改大小限制, this is 5M.

max_size=5242880

#此处增加限制文件后比缀名

Filter= ' \. (ZIP|RAR|O|OBJ|TAR|GZ) $ '

#Make sure that the log message contains some test


Svnlook=/usr/bin/svnlook


#LOGMSG = ' $SVNLOOK log-t "$TXN" "$REPOS" | grep "[A-za-z0-9]" | Wc-c '

logmsg= ' $SVNLOOK log-t "$TXN" $REPOS "| Wc-c '


If ["$LOGMSG"-lt 9];

Then

ECHO-E "NLog message Cann ' t be empty! You must input more than 8 chars as comment!. " 1>&2

Exit 1

Fi


files=$ ($SVNLOOK changed-t $TXN $REPOS |cut-d ""-F 4-)

#echo "$files" >&2

#echo "$r" >&2

#exit 1


Rc=0


echo "$files" | while read F;

Do

#check file type


Filesize= ' $SVNLOOK cat-t "$TXN" "$REPOS" "$f" | Wc-c '


If ["Filezie"-GT "$MAX _size"];

Then

echo "File $f is too large (must <+ $MAX _size) B" >&2

Exit 1

Fi

Done

#All checks Passed,so allow the commit.

If [$?-eq 1];

Then

Exit 1

Else

Exit 0

Fi


This article is from the "Scattered People" blog, please be sure to keep this source http://zouqingyun.blog.51cto.com/782246/1662285

SVN hook use

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.