Git 在提取到裸存储库时执行钩子

Git 在提取到裸存储库时执行钩子,git,Git,有一个简单的配置,有一个空的中央存储库,其中有一个“更新”钩子脚本 现在它不再是中央了。它应该轮询中央存储库以获取更改 如何使钩子脚本在这种情况下工作 一种解决方案是创建一个中间存储库,该存储库将从central提取并推送到旧的central。其他想法?我知道您在问题中没有提到使用Jenkins作为CI服务器,但这类事情的一个常见解决方案是使用它的 当将新提交推送到repo时,可以使用脚本触发器 有关如何在推送时触发作业的更多信息,请参阅本文:从问题中获得了一些有用的线索 我们的想法是用git-

有一个简单的配置,有一个空的中央存储库,其中有一个“更新”钩子脚本

现在它不再是中央了。它应该轮询中央存储库以获取更改

如何使钩子脚本在这种情况下工作


一种解决方案是创建一个中间存储库,该存储库将从central提取并推送到旧的central。其他想法?

我知道您在问题中没有提到使用Jenkins作为CI服务器,但这类事情的一个常见解决方案是使用它的

当将新提交推送到repo时,可以使用脚本触发器


有关如何在推送时触发作业的更多信息,请参阅本文:

从问题中获得了一些有用的线索

我们的想法是用
git-remote-update
更新这个存储库,并将其包装到启动
post-receive
钩子的脚本中<代码>远程更新.sh:

#!/bin/bash

git_dir=$(git rev-parse --git-dir) || exit
cd "$git_dir"

declare -A before after all

# create the 'before' list
while read commit_hash refspec; do
    before[$refspec]="$commit_hash"
    all[$refspec]=''
done < <(git show-ref --heads)

# do the remote update
git remote update --prune

# create the 'after' list
while read commit_hash refspec; do
    after[$refspec]="$commit_hash"
    all[$refspec]=''
done < <(git show-ref --heads)

# see if there were any changes, and if so, run the post-receive hook
changes=0
for refspec in "${!all[@]}"; do
    [ "${before[$refspec]}" != "${after[$refspec]}" ] && { changes=1; break; }
done

if [ "$changes" == "1" ]; then
    none="$(printf "%0.s0" {1..40})" # forty zeroes, or git's "don't care" ref
    for refspec in "${!all[@]}"; do
        # if the refspec changed, pass it to the post-receive hook
        [ "${before[$refspec]}" != "${after[$refspec]}" ] && \
            echo "${before[$refspec]:-$none} ${after[$refspec]:-$none} $refspec"
    done | GIT_DIR="$git_dir" hooks/post-receive
fi
当然,这可以正确完成,并防止在失败时获取

有更清洁的解决方案吗?

使用cron触发并不难(甚至更容易)。但如果我在回购协议中触发回迁,钩子就不会执行。如果我触发推式回购,则需要有一个临时存储库,从central提取,然后推式回购。
#!/bin/bash

while read oldrev newrev refname; do
    GIT_DIR="$GIT_DIR" hooks/update "$refname" "$oldrev" "$newrev"
done