SVN interceptors not working

I have a branch and backbone server repository. An affiliate is all the repositories of team members. I am trying to svn hooks

only use in my repo under the branch, but doesn't seem to work fine. The following are the steps I tried to get closer to:

  • retrieved my_repo

    from remote serverbranch/my_repo

  • since the local repo has my_repo

    no content, I created a new svn repo locally and copied everything including the folder /hooks

    to my_repo

    .

  • I created an empty file in my_repo

    and added a line of text. Then svn add

    this file.

  • changed the file my_repo/hooks/pre-commit.tmpl

    and made it always not transmit error code 1. Now it looks like this:

#! / bin / sh
exit 1
  • copy pre-commit.tmpl

    for pre-commit and add permission to do pre-commit for yourself

  • The server contains other people, now the server structure is similar:

- server
    - branch
        - my_repo
            - myfile
            - hooks
                - pre-commit
        - Tom repo
        - other team member repo
    - trunk
  • in the checkout repo I committed the changes using: svn commit -m "dumb change"

Now from here I would not be able to commit and it should give me an error with code 1 right? But I can't see anything.

  • Then I tried to set the hooks folder at the top level and at the same level as the branch and trunk. that is, the structure looks like this:
-server
    - branches
        - my_repo
            - myfile
        - Tom repo
        - other team member repo
    - trunk
    - hooks
        - pre-commit

But still doesn't work. Sigh...

HOWEVER, with David's help, I figured out what to do and what was wrong: 1. To highlight: the ownership of the hooks folder must be the same as the one created in the repository. So I had to ask the owner to add the hooks files to the server. I didn't create a repository on the server, so the files are invisible in my working directory. 2. Now, here's what I've tried:

  1) on my own Linux system, I `svnadmin create` a new repository, maybe called test_server: in that there is folders: confs, db, hooks, locks; files: format, readme.txt
  2) on the same level, mkdir a new folder (called working_dir) as your local working directory and checkout from the test_server. Now the working_dir contains a folder called test_server and it empty. You can't see any of the folders or files in step 1
  3) modify the test_server hooks file as described above. 
  4) try to add a file and add a new line to the file in the working_dir / test_server folder and commit. 
  5) now you should see commit failed with message: svn: Commit blocked by pre-commit hook (exit code 1) with no output. 

Thanks a lot to David and someone has posted comments before!

+3


source to share


4 answers


When you run the hook, STDOUT (which is usually generated by a statement echo

) is disabled. This means that your script cannot use STDOUT to print anything, even if redirected to a file.

Instead, you need to open a different file descriptor instead of using 1

(STDOUT). You can use the command exec

to open another file descriptor and then pipe that to the file:

exec 4> $my_file  #Opening my_file for writing
echo "This is going to $my_file" >&4

      

STDERR is also redirected. The STDERR output is collected and sent back to the calling client, but only when the hook returns a non-zero exit code. This gives you a way to contact the customer why the error was unsuccessful.

You also need to be careful, because the environment in which the hook operates is cleared. Even $PATH

is null.

Here are some of the reasons why a hook script works fine from the command line, but not when executed as a hook.

If you don't believe the hook works, just set it to exit with a non-zero exit code. If you get a message from Subversion that the transaction failed, you know that a hook script is being executed.

I also recommend using at least svnserve

Subversion to act as a server, even if you only use one repository. I never use file://

, even though I'm the only one using the repository. The process is svnserve

pretty easy to use and pretty easy.

Also, never use svn

hook in scripts. Use instead svnlook

.




Adding

I want to be very, very clear. We need to agree with some definitions:

  • The SERVER is the machine that the Subversion repository is running on. You used the command svnadmin create foo

    to create a directory foo

    that will act as the repository itself.
  • REPOSITORY DIRECTORY is the directory on the server created by the command svnadmin create

    . This is the SERVER SIDE of the repository. You may not see the files you checked out in Subversion. Instead, you will see a directory hooks

    and a directory db

    . This is what the server uses to track changes.
  • The WORKING DIRECTOR is the directory that you made svn checkout

    to check out a specific revision of your project.
  • REPOSITORY is a VIRTUAL kind of REPOSITORY directory that you get when you use various commands svn

    such as svn ls

    or svn log

    or svn co

    . This is NOT a REPOSITORY DIRECTOR, but a kind of repository.

Ok, now we have decided:

Hook scripts are stored in the REPOSITORY directory in the directory hooks

. When you create the REPOSITORY LIST, there will already be a subdirectory named hooks

with some templates for hook scripts. They will have a suffix *.tmpl

. To make the hook you need to replace one of these scripts with your hook script and remove the suffix *.tmpl

. The script hook must be executable and owned by the user running the Subversion SERVER process. (The user is running under control httpd

or command svnserve

on the server).

Hooks for all storage. You can't say that a hook doesn't fire only if a specific branch is affected. However, your hook script can see where the file is located and take action based on that. I have a pre-commit hook that does exactly that. It uses a control file to determine the action to take based on the location of the file. However, every time a commit occurs, this hook fires even if it doesn't need anything.

I hope this answers your questions.

+6


source


Have you tried using the output file somewhere else, for example /tmp

? It looks like you are trying to write back to your working directory, so maybe the script hook doesn't have access?



Note that the hook will execute as any user running the SVN server process, not the SVN client. So if you are using Apache WebDAV type access, it will be an Apache user (I think); if SSH access is used, this is the user specified in the syntax svn+ssh://user@path

;

+1


source


changed the hook / pre-commit.tmpl file and now it looks like

The pre-commit key should be named simply pre-commit. Pre-commit.tmpl is just a sample file and will never run.

0


source


After reading your question, I feel a little confused. I was here to make sure your understanding is correct:

There is no such thing as a "checked out repo" in Subversion. We have a repo (usually on a remote server), and after we have checked out that repo, we have a local working copy . Hooks are something that happens in the repository, not a local working copy.

From your step descriptions, this is what I get:

  • checked out from remote repository: remote server

  • Since the processed working copy has no content, I created a local copy of svn locally and copied everything, including the / hooks folder, into my checking working copy.

  • I created an empty file in the checked out working copy and added a line of text. Then svn add this file.

  • changed the hook / pre-commit.tmpl file in working copy and now it looks like this: (removed)

  • add execute permission for all users and copy pre-commit.tmpl for pre-commit (all this happens in working copy)

  • in the checked out working copy I committed the changes using: svn commit -m "dumb change"

If my understanding is correct, you just misunderstood the use of the hook. A hook is something pushed into the repository, not a working copy. The hook runs on the repository machine when you do (or do other things), not on your local machine.

0


source







All Articles