简体   繁体   English

错误 Windows Docker git: cd: .git: Not a directory

[英]Error in Windows Docker git: cd: .git: Not a directory

I have a Windows 10 host with a mcr.microsoft.com/do.net/framework/sdk:4.8-windowsservercore-ltsc2019 Docker image,我有一个 Windows 10 主机,带有mcr.microsoft.com/do.net/framework/sdk:4.8-windowsservercore-ltsc2019 Docker 图像,

git was installed via git 通过安装

RUN powershell.exe -ExecutionPolicy RemoteSigned `
  iex (new-object net.webclient).downloadstring('https://get.scoop.sh'); `
  scoop install python git

My git repo has submodules.我的 git 回购有子模块。 When I checkout the repo locally and try to build it via当我在本地签出回购并尝试通过构建它时

docker run --rm -it -v %cd%:C:\Temp -w C:\Temp buildtools2019 cmd.exe /C build.bat

I get the following error when git tries to update submodules (I use CMake as a build system):当 git 尝试更新子模块时出现以下错误(我使用 CMake 作为构建系统):

-- Submodule update
/mingw64/libexec/git-core/git-sh-setup: line 365: cd: .git: Not a directory
Unable to determine absolute path of git directory
CMake Error at CMakeLists.txt:47 (message):
  git submodule update --init failed with 1, please checkout submodules

But when I just start the container, make git clone inside the container and then execute my batch script, git has no problems.但是当我刚启动容器时,在容器git clone然后执行我的批处理脚本,git 没有问题。 What is the difference between the cloned repo and the mapped one?克隆的回购和映射的回购有什么区别?

Edit: Mapped folder list:编辑:映射文件夹列表:

PS C:\TEMP> dir


    Directory: C:\TEMP


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        1/27/2022   6:59 AM                .git
d-----        1/26/2022   6:01 PM                src
-a----        1/26/2022   6:01 PM             88 .gitmodules
-a----        1/26/2022   6:01 PM            162 build.bat

This is the routine where the issue occurs:这是发生问题的例程:

# Make sure we are in a valid repository of a vintage we understand,
# if we require to be in a git repository.
git_dir_init () {
        GIT_DIR=$(git rev-parse --git-dir) || exit
        if [ -z "$SUBDIRECTORY_OK" ]
        then
                test -z "$(git rev-parse --show-cdup)" || {
                        exit=$?
                        gettextln "You need to run this command from the toplevel of the working tree." >&2
                        exit $exit
                }
        fi
        test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
                gettextln "Unable to determine absolute path of git directory" >&2
                exit 1
        }
        : "${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}"
}

I can change into any directory while I'm still in the shell, but from inside of this script, I can change only into the folders outside of the mounting point ie c:\TEMP .当我还在 shell 中时,我可以更改到任何目录,但是从这个脚本内部,我只能更改到安装点之外的文件夹,即c:\TEMP

I opened a ticket on git-for-windows project page.我在 git-for-windows 项目页面上开了一张票 The problem could be narrowed down to msys2 but the dubugging is stilll not finished.问题可以缩小到 msys2,但调试仍未完成。

For now, there is a workaround: use git 2.11.0.目前,有一个解决方法:使用 git 2.11.0。

ADD https://github.com/git-for-windows/git/releases/download/v2.11.0.windows.1/Git-2.11.0-64-bit.exe git.exe
RUN c:\git.exe /SP- /VERYSILENT /NORESTART /NOCANCEL /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS -Wait -NoNewWindow; `
        Remove-Item -Force git.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM