简体   繁体   中英

alternative to SVN hook that modifies the transaction

I need to do the following and i can only think of an svn hook solution but modifying the transaction in the hook is supposed to be bad:

We have a production repository and a test repository. I want to make sure that when someone commits to the production repository, they are sure about it and that it is not by mistake something they intended for the test repository. So I though of a pre-commit hook that denies the commit into the production repo if the commiter does not start the log message with the line "PRODUCTION", then strip the line out so that the rest of the log message remains.

Does this scenario justifies the use of the hook to modify (the log message of) the transaction? If not, in what way could this cause trouble? Can someone propose a better alternative?

You can edit the revision property in a post-commit hook that modifies that log message. That seems cleaner than modifying the transaction before it's completed.

I too was seeking examples of pre-commit hooks that modify svn:log since it explicitly says you can do so in the pre-commit.tmpl. My BASH pre-commit script for Subversion calls out to a Python script in order to set the log message by expanding the JIRA issue key to the JIRA issue Summary. I've found, even as of this writing, that there are NOT many examples and I've also found the majority of people believe it's a bad idea because they confound modifying non-versioned properties with modifying the transaction proper.

The only way that I've found to actually modify svn:log in a pre-commit hook is to use the Python bindings to the svn API, like they do in the FreeBSD project with the "log police" script. James Tauber explains this (although the post is dated because it's referring to svn 1.3) -- Google it because I can't post more links in this answer.

It's important to know that there are several different Python bindings to Subversion besides the python-subversion SWIG based wrapper that ships with Subversion itself (eg. SubvertPy). The PySVN project includes a 'transaction' interface which would give you the ability to modify svn:log in a pre-commit hook. It's actually somewhat documented as opposed to the standard python-subversion bindings.

It is perfectly alright to rollback a transaction in the hook script if the user does not adhere to the commit requirements.

http://www.waltercedric.com/java-j2ee-mainmenu-53/165-tools/1678-how-to-check-commit-comments-on-svn-commit.html

You can absolutely reject a commit during pre-commit if the user hasn't adhered to standards.

In addition, you CAN modify NON-VERSIONED properties during pre-commit. Examples of non-versioned properties are... svn:log, which you want to modify. I believe the rule is, if it is a revision-property, it's non-versioned, but if it' a file/directory property, it is versioned.

Revision properties are things like svn:log, svn:author, etc - and are typically applied at the revision at the root of the repository.

There are many example pre-commit hook scripts out there that modify svn:log during the commit. A quick example is FreeBSD's log-police.py , used in production in the repo supporting the core FreeBSD OS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM