Take the 2-minute tour ×

How to create a subversion server hook script that prevents people from committing changes if they don't own the lock on the file first?

Svn server is on windows.


P.S. Additional info in this question


share|improve this question
Belongs in serverfault.com –  Gonzalo Dec 18 '09 at 0:07
Isn't that the whole point of a lock on a file, is that so someone else cannot commit changes to that file? –  jaywon Dec 18 '09 at 0:07
@jaywon: The file isn't locked by anyone. I'm thinking it has svn:needs-lock set (because I saw this question originate from a previous). @Irfan: correct me if I'm wrong, but you're trying to deny committing svn:needs-lock files that aren't locked right? –  Sander Rijken Dec 18 '09 at 0:14
@Sander : Yes exactly –  Irfan Mulic Dec 18 '09 at 0:17
could you elaborate a bit more on what you are trying to achieve? Are you working on text files, binary or a combination? –  Ralph Willgoss Dec 18 '09 at 0:18

2 Answers 2

up vote 4 down vote accepted

Use a pre-commit hook. Pre-commit hook receives 2 arguments:

#   [2] TXN-NAME     (the name of the txn about to be committed)

You need to use svnlook to determine if there are svn:needs-lock files that aren't locked.

To determine the paths changed by this commit:

svnlook changed $1 --transaction $2

Loop through the files ($PATH as loop item) in 'changed' and determine svn:needs-lock, and if they're currently locked:

svnlook propget $REPOS-PATH svn:needs-lock $PATH
svnlook lock $1 $PATH

Write an to stderr and return non-zero to abort this commit when needed.

share|improve this answer
+1 for showing the pre-commit + property logic combined –  Ralph Willgoss Dec 18 '09 at 0:23
actually svnlook propget looks like this: svnlook propget $REPO_PATH propname $FILE_PATH –  Irfan Mulic Dec 23 '09 at 1:09

You can use <your repos directory>/hooks/pre-commit and use some batch scripting (or even a full blown program, as long as it's executable it will be fine). If it returns 0 the commit will be successful; otherwise it will fail.

See post-lock.tmpl in that same directory for an example.

# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client.   The hook
# program can use the 'svnlook' utility to help it examine the txn.
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
share|improve this answer

Your Answer


