gpt4 book ai didi

git clone git hooks 中的不同存储库造成麻烦

转载 作者:太空狗 更新时间:2023-10-29 13:01:23 26 4
gpt4 key购买 nike

我们有一个特定的要求,我们必须将所有到达的文件推送到某个分支。

我们计划通过 git hooks 特别是 commit-msg hook 来实现这一点。

这样做的同时,我们所做的是将分支克隆到临时位置 (/tmp/),然后在 git commit-msg Hook 中,尝试将到达的文件提交到某个分支。

但是现在发生的是我们看到/tmp/中的所有文件都已删除。

粗略的 commit-msg 脚本如下:-

#!/bin/bash
#
#!/usr/bin/env bash

#git config credential.helper store
REPOSRC="https://<USER>:<PASS>@<REPO_URL>"
LOCALREPO="<LOCAL_REPO_DIR>"

echo "Pulling code to temporarry location";

cd /tmp && git clone "${REPOSRC}" || (cd "${LOCALREPO}"; git pull;)

#here when I navigate to /tmp/<LOCALREPO> all files are listed as DELETED

git diff --cached --name-status | while read st file; do

echo "file == $file and status == $st";

if [ "$st" == "A" ]; then
cd "${LOCALREPO}" && git add "$file" && git commit "$file" -m "$COMMIT_MSG" && git push origin "$branch"
else
cd "${LOCALREPO}" && git commit "$file" -m "$COMMIT_MSG" && git push origin "$branch"
fi
done

这可能是什么根本原因?

编辑:

GIT_INDEX_FILE 显示发起提交 的索引文件路径,而不是/tmp/ 路径。有什么办法可以改变这个变量吗?索引文件也会打印类似 next-index-32419.lock 的内容。问候

最佳答案

每当 Hook 更改文件夹时,检查以下值很重要:

  • GIT_DIR (在你的案例中应该引用正确的 .git repo 文件夹)
  • GIT_WORK_TREE (它应该引用预期的文件夹)

这就是为什么对于任何 Git 命令,您都需要将 git 替换为:

git --work-tree=$(pwd) ...

(或/path/to/your/working/tree)

关于git clone git hooks 中的不同存储库造成麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49249945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com