Git:更新后挂钩,运行需要访问存储库中所有文件的脚本的脚本 [英] Git: Post-update hook that runs a script that needs access to all files in the repository

查看:119
本文介绍了Git:更新后挂钩,运行需要访问存储库中所有文件的脚本的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我陷入了两难的境地,因为每当远程存储库更新时(即,每当有人运行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.

推荐答案

首先,您可能想使用后接收挂钩而不是后更新.根据 githooks(5)手册页,接收后将取代更新后的内容.

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.

也就是说,您的钩子脚本是在.git/hooks子目录中执行的,因此,如果执行简单的操作

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

cd ..

您的脚本在git存储库的工作树中.例如,这是一个微型脚本,该脚本可以确保在您每次推送到远程git存储库时都会更新其工作树:

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."

请注意,您需要取消设置GIT_DIR环境变量.它是自动设置的,并且只要它设置好,所有git命令都将在该目录中运行-不管您在何处cd.

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.

这篇关于Git:更新后挂钩,运行需要访问存储库中所有文件的脚本的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆