代码之家  ›  专栏  ›  技术社区  ›  Matthew Iselin

Git:Post-update钩子,运行需要访问存储库中所有文件的脚本

  •  2
  • Matthew Iselin  · 技术社区  · 16 年前

    我现在有点进退两难,因为每当远程存储库更新时(即,每当有人运行git push时),我需要一个脚本来运行,该脚本从存储库中的文件构建包。然后将这些包放在git服务器上的一个目录中,该目录通过HTTP向客户端公开,以供将来使用。

    问题是,我不确定如何在更新后挂钩中访问存储库中的文件。

    如果有人能提供一些见解,我们将不胜感激。

    2 回复  |  直到 16 年前
        1
  •  3
  •   ryanday    14 年前

    首先,您可能希望使用post接收挂钩而不是post更新。根据 githooks(5) 手册页,接收后取代更新后。

    cd ..
    

    您的脚本位于git存储库的工作树中。例如,这里有一个小脚本,它可以确保每当您推送到存储库时,远程git存储库的工作树都会更新:

    #!/bin/sh
    export GIT_DIR=
    cd ..
    echo "Resetting working tree..."
    git reset --hard
    echo "Finished resetting working tree."
    

        2
  •  1
  •   Fire Crow    16 年前

    如果远程repsitory是裸共享repo,则没有文件副本。 您可以更改此设置,然后只需运行自动签出。

    我使用以下内容的目的与您指定的完全相同

    这是一篇博客文章,向我展示了如何设置它 http://toroid.org/ams/git-website-howto

    下面是我的缩写注释

                # create the repo with files that live in a seperate folder
                cd /share/proj/all/$1/repo
                git --bare init --shared
                git config core.worktree ../actual
                git config core.bare false
                git config receive.denycurrentbranch ignore
                # add a hook to checkout the repo into the files directory automatically on push
                echo "#!/bin/sh" > hooks/post-receive
                echo "git checkout -f" >> hooks/post-receive
                chmod +x hooks/post-receive
    
    推荐文章