SVN挂钩不工作

SVN挂钩不工作,svn,hook,commit,Svn,Hook,Commit,我有一个分支和主干的服务器存储库。分支是所有团队成员的存储库。我试图仅在分支下的回购协议中使用svn钩子,但似乎效果不好。以下是我尝试的步骤: 已从远程服务器的分支机构/my_repo签出my_repo 由于本地repomy_repo没有任何内容,我在本地创建了一个新的svn repo,并将所有内容(包括/hooks文件夹)复制到my_repo 我在my_repo中创建了一个空文件,并添加了一行文本。然后svn添加该文件 修改了my_repo/hooks/pre commit.tmpl文件,并使

我有一个分支和主干的服务器存储库。分支是所有团队成员的存储库。我试图仅在分支下的回购协议中使用
svn钩子
,但似乎效果不好。以下是我尝试的步骤:

  • 已从远程服务器的分支机构/my_repo签出
    my_repo

  • 由于本地repo
    my_repo
    没有任何内容,我在本地创建了一个新的svn repo,并将所有内容(包括
    /hooks
    文件夹)复制到
    my_repo

  • 我在
    my_repo
    中创建了一个空文件,并添加了一行文本。然后
    svn添加该文件

  • 修改了
    my_repo/hooks/pre commit.tmpl
    文件,并使其始终不传递错误代码1。现在看来:

  • 在签出的回购中,我使用以下命令提交更改:
    svn commit-m“dumb change”
  • 现在,从这里我应该不能提交,它应该给我一个代码1的错误,对吗?但我在任何地方都看不到

  • 然后我试着把hooks文件夹放在顶层,和branch和trunk放在同一层。i、 e.结构如下:
  • -服务器 -分支机构 -我的报告 -我的文件 -汤姆的回购协议 -其他团队成员的回购协议 -树干 -钩子 -预提交 但是,仍然不起作用。叹息

    然而,在大卫的帮助下,我想出了该怎么做,出了什么问题: 1.突出显示:hooks文件夹的所有权应与创建存储库的人相同。因此,我不得不要求所有者将hooks文件添加到服务器。我没有在服务器上创建存储库,因此这些文件在我的工作目录中是不可见的。 2.下面是我试过的:

    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's empty. You can't see any of the folders or files in step 1 3) modify the test_server's 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. 1) 在我自己的Linux系统上,我创建了一个新的存储库,可能叫做test_server:其中有文件夹:confs、db、hook、locks;文件:格式,readme.txt 2) 在同一级别上,mkdir创建一个新文件夹(称为working_dir)作为本地工作目录,并从test_服务器进行签出。现在,工作目录包含一个名为test\u server的文件夹,它是空的。您在步骤1中看不到任何文件夹或文件 3) 如上所述修改测试服务器的hooks文件。 4) 尝试在working_dir/test_server文件夹中添加文件并向文件添加新行,然后提交。 5) 现在您应该看到提交失败,消息为:svn:commit被预提交挂钩(退出代码1)阻止,没有输出。
    非常感谢David和之前发表评论的人

    您是否尝试过在其他地方使用输出文件,如
    /tmp
    ?听起来好像您正试图写回您的工作副本目录,所以可能钩子脚本没有访问权限

    请注意,钩子将作为SVN服务器进程运行的任何用户运行,而不是SVN客户端。因此,如果您使用的是apachewebdav类型的访问,那么它将是Apache的用户(我认为);如果使用SSH访问,则是
    svn中列出的用户+ssh://user@路径
    语法

    修改了hooks/pre-commit.tmpl文件,现在看起来


    pre-commit钩子需要命名为just-pre-commit。pre-commit.tmpl只是一个示例文件,永远不会运行。

    阅读您的问题后,我感到有点困惑。我来这里只是为了确保你的理解是正确的:

    Subversion中没有“签出回购”这样的东西。我们有repo(通常在远程服务器中),在我们从该repo签出后,我们有一个本地工作副本。钩子是存储库中发生的事情,而不是本地工作副本

    从您对步骤的描述中,我得到了以下结论:

  • 从远程存储库签出:远程服务器

  • 由于签出的工作副本没有任何内容,我在本地创建了一个新的svn repo,并将所有内容(包括/hooks文件夹)复制到签出的工作副本中

  • 我在签出的工作副本中创建了一个空文件,并添加了一行文本。然后svn添加这个文件

  • 修改了工作副本中的hooks/pre-commit.tmpl文件,现在看起来像:(已删除)

  • 向所有用户添加执行许可,并将pre-commit.tmpl复制到pre-commit(这些都发生在工作副本中)

  • 在签出的工作副本中,我使用:svn commit-m“dumb change”提交了更改


  • 如果我的理解是正确的,你只是误解了胡克的用法。钩子是放在存储库中的东西,而不是工作副本。当您提交(或执行其他操作)时,钩子在存储库计算机上运行,而不是在本地计算机上运行。

    当您运行钩子时,STDOUT(通常由
    echo
    语句生成)被禁用。这意味着您的脚本不能使用STDOUT打印任何内容,即使它已重定向到文件

    相反,您需要打开另一个文件描述符,而不是使用
    1
    (STDOUT)。您可以使用
    exec
    命令打开另一个文件描述符,然后将其导入文件:

    exec 4> $my_file  #Opening my_file for writing
    echo "This is going to $my_file" >&4
    
    STDERR也被重定向。STDERR的输出被收集并发送回调用客户机,但仅当钩子返回非零退出代码时。这为您提供了一种与客户机沟通钩子失败原因的方法

    您还必须小心,因为钩子运行的环境已被清除。甚至
    $PATH
    也为空

    这就是为什么钩子脚本可以从命令行正常运行,但在作为钩子执行时却不能正常运行的一些原因

    如果您认为钩子不起作用,只需将其设置为以非零退出代码退出即可。如果您从Subversion收到一条消息,表明事务失败,那么您就知道执行了钩子脚本

    我还建议您至少使用
    svnserve
    作为Subversion服务器,即使您是唯一使用 -server - branches - my_repo - myfile - Tom's repo - other team member's repo - trunk - hooks - pre-commit 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's empty. You can't see any of the folders or files in step 1 3) modify the test_server's 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.
    exec 4> $my_file  #Opening my_file for writing
    echo "This is going to $my_file" >&4
    
    cp post-commit.tmpl post-commit
    chmod +x post-commit