pre-commit.tmpl 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. # PRE-COMMIT HOOK
  3. #
  4. # The pre-commit hook is invoked before a Subversion txn is
  5. # committed. Subversion runs this hook by invoking a program
  6. # (script, executable, binary, etc.) named 'pre-commit' (for which
  7. # this file is a template), with the following ordered arguments:
  8. #
  9. # [1] REPOS-PATH (the path to this repository)
  10. # [2] TXN-NAME (the name of the txn about to be committed)
  11. #
  12. # [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
  13. #
  14. # If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
  15. # single newline), the lines following it are the lock tokens for
  16. # this commit. The end of the list is marked by a line containing
  17. # only a newline character.
  18. #
  19. # Each lock token line consists of a URI-escaped path, followed
  20. # by the separator character '|', followed by the lock token string,
  21. # followed by a newline.
  22. #
  23. # If the hook program exits with success, the txn is committed; but
  24. # if it exits with failure (non-zero), the txn is aborted, no commit
  25. # takes place, and STDERR is returned to the client. The hook
  26. # program can use the 'svnlook' utility to help it examine the txn.
  27. #
  28. # *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
  29. # *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
  30. #
  31. # This is why we recommend using the read-only 'svnlook' utility.
  32. # In the future, Subversion may enforce the rule that pre-commit
  33. # hooks should not modify the versioned data in txns, or else come
  34. # up with a mechanism to make it safe to do so (by informing the
  35. # committing client of the changes). However, right now neither
  36. # mechanism is implemented, so hook writers just have to be careful.
  37. #
  38. # The default working directory for the invocation is undefined, so
  39. # the program should set one explicitly if it cares.
  40. #
  41. # On a Unix system, the normal procedure is to have 'pre-commit'
  42. # invoke other programs to do the real work, though it may do the
  43. # work itself too.
  44. #
  45. # Note that 'pre-commit' must be executable by the user(s) who will
  46. # invoke it (typically the user httpd runs as), and that user must
  47. # have filesystem-level permission to access the repository.
  48. #
  49. # On a Windows system, you should name the hook program
  50. # 'pre-commit.bat' or 'pre-commit.exe',
  51. # but the basic idea is the same.
  52. #
  53. # The hook program runs in an empty environment, unless the server is
  54. # explicitly configured otherwise. For example, a common problem is for
  55. # the PATH environment variable to not be set to its usual value, so
  56. # that subprograms fail to launch unless invoked via absolute path.
  57. # If you're having unexpected problems with a hook program, the
  58. # culprit may be unusual (or missing) environment variables.
  59. #
  60. # CAUTION:
  61. # For security reasons, you MUST always properly quote arguments when
  62. # you use them, as those arguments could contain whitespace or other
  63. # problematic characters. Additionally, you should delimit the list
  64. # of options with "--" before passing the arguments, so malicious
  65. # clients cannot bootleg unexpected options to the commands your
  66. # script aims to execute.
  67. # For similar reasons, you should also add a trailing @ to URLs which
  68. # are passed to SVN commands accepting URLs with peg revisions.
  69. #
  70. # Here is an example hook script, for a Unix /bin/sh interpreter.
  71. # For more examples and pre-written hooks, see those in
  72. # the Subversion repository at
  73. # http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
  74. # http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
  75. REPOS="$1"
  76. TXN="$2"
  77. # Make sure that the log message contains some text.
  78. SVNLOOK=/usr/local/bin/svnlook
  79. $SVNLOOK log -t "$TXN" "$REPOS" | \
  80. grep "[a-zA-Z0-9]" > /dev/null || exit 1
  81. # Check that the author of this commit has the rights to perform
  82. # the commit on the files and directories being modified.
  83. commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
  84. # All checks passed, so allow the commit.
  85. exit 0