Git:更新后挂钩,运行需要访问存储库中所有文件的脚本

发布于 2024-08-07 07:42:32 字数 189 浏览 3 评论 0原文

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

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

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

I'm running into a bit of dilemma at the moment in that I need a script to run whenever the remote repository is updated (ie, whenever someone runs git push) that builds packages from the files in the repository. These packages are then placed into a directory on the git server that's exposed to clients over HTTP for future use.

The problem is, I'm not sure how to access the files in the repository in the post-update hook.

If anyone can give some insight, it would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浸婚纱 2024-08-14 07:42:32

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

也就是说,你的钩子脚本是在 .git/hooks 子目录中执行的,所以如果你做一个简单的操作,

cd ..

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

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

请注意,您需要取消设置 GIT_DIR 环境变量;它是自动设置的,只要设置了,所有 git 命令都将在该目录中运行 - 无论您 cd 到哪里。

First of all, you might want to use the post-receive hook instead of post-update. According to the githooks(5) man page, post-receive supersedes post-update.

That said, your hook script is executed in the .git/hooks subdirectory, so if you do a simple

cd ..

your script is in the working tree of the git repository. For instance, here's a tiny script which makes sure that the working tree of the remote git repository is updated whenever you push to the repository:

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

Note that you need to un-set the GIT_DIR environment variable; it's automatically set, and as long as its set all git commands will be run in that directory - no matter where you cd'ed to.

心作怪 2024-08-14 07:42:32

如果您的远程存储库是裸露的共享存储库,则没有文件的副本。
您可以更改此设置,然后您只需运行自动结帐即可。

如果您打包 hte 文件,最好也将存储库放在单独的目录中,

我使用以下内容来达到您指定的确切目的,

这里是向我展示如何设置它的博客文章
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

If your remote repsitory is a bare shared repo, then there is no copy of the files.
you can change this, and then you'll just have to run an auto checkout.

if your packaging hte files, best to have the repo in a seperate directory too

I use the following for the exact purpose you've named

here is the blog post that showed me how to set it up
http://toroid.org/ams/git-website-howto

here are my abbrieviated notes below

make a directory outside the repo and put the working tree there, then make it no longer a bare repo so there is a copy of the files, then run a before you run your packaging script

            # 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文