Error in Windows Docker git: cd: .git: Not a directory

Viewed 411

I have a Windows 10 host with a mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019 Docker image,

git was installed via

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

My git repo has submodules. 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):

-- 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. 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 i.e. c:\TEMP.

1 Answers

I opened a ticket on git-for-windows project page. The problem could be narrowed down to msys2 but the dubugging is stilll not finished.

For now, there is a workaround: use 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
Related