使用 post-update hook 在另一个 repo 上执行 'git pull' 时得到“fatal: not a git repository: '.'”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4043609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:22:09  来源:igfitidea点击:

getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo

gitgithooks

提问by Ty W

I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best.

我是 git 的新手,所以如果我在这里误用了术语,我深表歉意(并请纠正我),但我会尽力而为。

I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a web server. I've tried to pattern it after this article. I want the development working copy to be updated whenever the hub repo is pushed to. I'm under the impression that the proper hook for this is post-update, which I have created like so:

我正在尝试在 Web 服务器上设置一个裸 git repo(集线器)和一个开发站点工作副本(prime)。我已经尝试在这篇文章之后对其进行模式化。我希望在推送集线器存储库时更新开发工作副本。我的印象是,正确的钩子是post-update,我是这样创建的:

#!/bin/sh
whoami
cd /path/to/working-copy/
RET=`git pull`
echo $RET

Update

更新

When I push changes from my local repo to the bare hub I get the following output from the post-update script:

当我将更改从本地存储库推送到裸集线器时,我从更新后脚本中获得以下输出:

remote: sites
remote: fatal: Not a git repository: '.'

However if I SSH into the server as user 'sites' and execute this script manually it works great Any ideas as to what might be going wrong with this hook or script?

但是,如果我以用户“站点”的身份通过 SSH 连接到服务器并手动执行此脚本,则效果很好 关于此挂钩或脚本可能出现什么问题的任何想法?

回答by Ty W

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR

这是最终起作用的脚本。我认为我最初缺少的阻止它远程工作的一点是unset GIT_DIR

#!/bin/sh
cd /path/to/working-copy/ || exit
unset GIT_DIR
git pull repo branch

exec git-update-server-info

回答by Geraldo Luis da Silva Ribeiro

Try instead:

试试吧:

#!/bin/sh
cd /path/to/working-copy/
env -i git pull

回答by Zvika Naveh

Despite that unset GIT_DIR just works.

尽管未设置 GIT_DIR 仍然有效。

the problem occurs when you set GIT_DIR wrongly somewhere else.

当您在其他地方错误地设置 GIT_DIR 时会出现问题。

you can just add that instead: GIT_DIR=.git/ It will work

你可以添加它: GIT_DIR=.git/ 它会工作

回答by ThorSummoner

In my case I had specified a working tree, and this breaks on some commands, like pull(or more precisely fetch).

在我的例子中,我指定了一个工作树,这会中断一些命令,比如pull(或更准确地说fetch)。

To unset the working tree if it is in your git config is via:

要取消设置工作树(如果它在您的 git 配置中)是通过:

git config --unset core.worktree

(There are other ways to set a work tree)

(还有其他设置工作树的方法)

Important to note,

重要的是要注意,

There is next to no change of this being your problem unless you yourself dug this hole around you by using a custom worktree in the first place.

除非您自己首先使用自定义工作树在您周围挖了这个洞,否则您的问题几乎没有变化。

Banter:

嘲笑:

This implies to me that git internals use paths relative to the worktree + .git/in some cases. In my experience worktrees are not well supported whatsoever, except by the most fundamental parts of git. I have not experimented thoroughly, Git would probably behave if I set whatever the git directory config variable is properly, which I have not played with.

这对我来说意味着 git 内部.git/在某些情况下使用相对于工作树 + 的路径。根据我的经验,工作树并没有得到很好的支持,除了 git 最基本的部分。我还没有进行彻底的实验,如果我设置了正确的 git 目录配置变量,Git 可能会表现得很好,我没有玩过。

回答by Ariejan

You probably have a permissions issue. I'm not sure how you have setup your bare git repo, but if it's running under the gituser, make sure that gituser is allowed to perform the git pullin your project directory.

您可能有权限问题。我不确定您是如何设置裸 git 存储库的,但是如果它在git用户下运行,请确保git允许该用户git pull在您的项目目录中执行。

Optionally try this to find out what user you are when the hook is run:

可以选择尝试此操作以找出运行挂钩时您是哪个用户:

echo `whoami`