pre-commit.tmpl 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # The default working directory for the invocation is undefined, so
  13. # the program should set one explicitly if it cares.
  14. #
  15. # If the hook program exits with success, the txn is committed; but
  16. # if it exits with failure (non-zero), the txn is aborted, no commit
  17. # takes place, and STDERR is returned to the client. The hook
  18. # program can use the 'svnlook' utility to help it examine the txn.
  19. #
  20. # On a Unix system, the normal procedure is to have 'pre-commit'
  21. # invoke other programs to do the real work, though it may do the
  22. # work itself too.
  23. #
  24. # *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
  25. # *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
  26. #
  27. # This is why we recommend using the read-only 'svnlook' utility.
  28. # In the future, Subversion may enforce the rule that pre-commit
  29. # hooks should not modify the versioned data in txns, or else come
  30. # up with a mechanism to make it safe to do so (by informing the
  31. # committing client of the changes). However, right now neither
  32. # mechanism is implemented, so hook writers just have to be careful.
  33. #
  34. # Note that 'pre-commit' must be executable by the user(s) who will
  35. # invoke it (typically the user httpd runs as), and that user must
  36. # have filesystem-level permission to access the repository.
  37. #
  38. # On a Windows system, you should name the hook program
  39. # 'pre-commit.bat' or 'pre-commit.exe',
  40. # but the basic idea is the same.
  41. #
  42. # The hook program typically does not inherit the environment of
  43. # its parent process. For example, a common problem is for the
  44. # PATH environment variable to not be set to its usual value, so
  45. # that subprograms fail to launch unless invoked via absolute path.
  46. # If you're having unexpected problems with a hook program, the
  47. # culprit may be unusual (or missing) environment variables.
  48. #
  49. # Here is an example hook script, for a Unix /bin/sh interpreter.
  50. # For more examples and pre-written hooks, see those in
  51. # the Subversion repository at
  52. # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and
  53. # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/
  54. REPOS="$1"
  55. TXN="$2"
  56. # Make sure that the log message contains some text.
  57. SVNLOOK=/usr/local/bin/svnlook
  58. $SVNLOOK log -t "$TXN" "$REPOS" | \
  59. grep "[a-zA-Z0-9]" > /dev/null || exit 1
  60. # Check that the author of this commit has the rights to perform
  61. # the commit on the files and directories being modified.
  62. commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
  63. # All checks passed, so allow the commit.
  64. exit 0