/hooks/pre-lock.tmpl

http://labaratorijske2011.googlecode.com/ · Shell · 71 lines · 16 code · 9 blank · 46 comment · 2 complexity · 3cdc47f8d2bcf55576b30d60cf2608aa MD5 · raw file

  1. #!/bin/sh
  2. # PRE-LOCK HOOK
  3. #
  4. # The pre-lock hook is invoked before an exclusive lock is
  5. # created. Subversion runs this hook by invoking a program
  6. # (script, executable, binary, etc.) named 'pre-lock' (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] PATH (the path in the repository about to be locked)
  11. # [3] USER (the user creating the lock)
  12. # [4] COMMENT (the comment of the lock)
  13. # [5] STEAL-LOCK (1 if the user is trying to steal the lock, else 0)
  14. #
  15. # If the hook program outputs anything on stdout, the output string will
  16. # be used as the lock token for this lock operation. If you choose to use
  17. # this feature, you must guarantee the tokens generated are unique across
  18. # the repository each time.
  19. #
  20. # The default working directory for the invocation is undefined, so
  21. # the program should set one explicitly if it cares.
  22. #
  23. # If the hook program exits with success, the lock is created; but
  24. # if it exits with failure (non-zero), the lock action is aborted
  25. # and STDERR is returned to the client.
  26. # On a Unix system, the normal procedure is to have 'pre-lock'
  27. # invoke other programs to do the real work, though it may do the
  28. # work itself too.
  29. #
  30. # Note that 'pre-lock' must be executable by the user(s) who will
  31. # invoke it (typically the user httpd runs as), and that user must
  32. # have filesystem-level permission to access the repository.
  33. #
  34. # On a Windows system, you should name the hook program
  35. # 'pre-lock.bat' or 'pre-lock.exe',
  36. # but the basic idea is the same.
  37. #
  38. # Here is an example hook script, for a Unix /bin/sh interpreter:
  39. REPOS="$1"
  40. PATH="$2"
  41. USER="$3"
  42. # If a lock exists and is owned by a different person, don't allow it
  43. # to be stolen (e.g., with 'svn lock --force ...').
  44. # (Maybe this script could send email to the lock owner?)
  45. SVNLOOK=/usr/local/bin/svnlook
  46. GREP=/bin/grep
  47. SED=/bin/sed
  48. LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
  49. $GREP '^Owner: ' | $SED 's/Owner: //'`
  50. # If we get no result from svnlook, there's no lock, allow the lock to
  51. # happen:
  52. if [ "$LOCK_OWNER" = "" ]; then
  53. exit 0
  54. fi
  55. # If the person locking matches the lock's owner, allow the lock to
  56. # happen:
  57. if [ "$LOCK_OWNER" = "$USER" ]; then
  58. exit 0
  59. fi
  60. # Otherwise, we've got an owner mismatch, so return failure:
  61. echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2
  62. exit 1