Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First call git checkout does not work in Windows Docker container in mounted host volume folder #2778

Open
1 task
mariuszkochanowski opened this issue Aug 3, 2020 · 10 comments

Comments

@mariuszkochanowski
Copy link

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

git version 2.28.0.windows.1
cpu: x86_64
built from commit: 77982caf269b7ee713a76da2bcf260c34d3bf7a7
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19041.388]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

** insert your machine's response here **
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

Running Git for Windows in a Windows Container directly on a volume mount point.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

** insert your response here **

After 'git clone' first direct call of 'git checkout mybranchname' always ends witch error:
cannot lock ref 'refs/heads/mybranchname': unable to resolve reference 'refs/heads/mybranchname': Not a directory

Second call works properly.

It occours in  in mcr.microsoft.com/windows/servercore:2004 in mounted host volume folder.
It not occours in not mounted volume folder and directry in host machine

  • What did you expect to occur after running these commands?

** insert here **

  • What actually happened instead?

** insert here **

  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

** insert URL here **

@dscho
Copy link
Member

dscho commented Aug 11, 2020

Are you able to build Git? It would be interesting to instrument the code (read: litter it with debug print statements) and figure out where the actual root cause lies, and what error code is actually returned (and why). For starters, I would start with these code locations, if I were you:

$ git grep "unable to resolve reference" \*.c
refs/files-backend.c:                           strbuf_addf(err, "unable to resolve reference '%s'",
refs/files-backend.c:                           strbuf_addf(err, "unable to resolve reference '%s'",
refs/files-backend.c:                           strbuf_addf(err, "unable to resolve reference '%s'",
refs/files-backend.c:                   strbuf_addf(err, "unable to resolve reference '%s': "
refs/files-backend.c:                   strbuf_addf(err, "unable to resolve reference '%s': %s",
refs/files-backend.c:                   strbuf_addf(err, "unable to resolve reference '%s': %s",

@mariuszkochanowski
Copy link
Author

mariuszkochanowski commented Aug 12, 2020

Error message is from line 706 of refs/files-backend.c file.
I tested it with 2 branch names:

  1. myfeature
  2. feature/myfeature
    Error occured only in second case in mounted host volume folder.

More detailed info:

after git clone command of repository:

a ) in mounted volume also in mounted host volume folder
first call command 'git checkout feature/myfeaturename'
creates folder .git\refs\heads\featue
and ends with mentioned error 'unable to resolve reference'

second call command 'git checkout feature/myfeaturename'
creates file .git\refs\heads\featue\myfeaturename

b) directly in windows host machine:
first call command 'git checkout feature/myfeaturename'
immediately creates file .git\refs\heads\featue\myfeaturename
and ends without error

@dscho
Copy link
Member

dscho commented Aug 14, 2020

Error message is from line 706 of refs/files-backend.c file.

So something in files_read_raw_ref() does not work, most likely creating the directory? My wild guess is that safe_create_leading_directories() fails to create the directory...

@dscho
Copy link
Member

dscho commented Aug 25, 2020

@mariuszkochanowski did you get a chance to dig further?

@mariuszkochanowski
Copy link
Author

I've prepared a reproducible example:
https://github.com/mariuszkochanowski/GitIssue.git
Just checkout branch develop or master and run docker-compose_up.sh
It requires docker for windows. It will download mcr.microsoft.com/windows/servercore:2004 image and git for windows installer.
Output from docker console:

C:\>cd c:\data
c:\data>RMDIR GitIssue /S /Q
The system cannot find the file specified.
c:\data>git clone https://github.com/mariuszkochanowski/GitIssue.git
Cloning into 'GitIssue'...
c:\data>cd GitIssue
c:\data\GitIssue>git fetch
c:\data\GitIssue>git checkout "feature/branchname"
fatal: cannot lock ref 'refs/heads/feature/branchname': unable to resolve reference 'refs/heads/feature/branchname': Not a directory

@dscho
Copy link
Member

dscho commented Aug 26, 2020

@mariuszkochanowski do you think you will have a chance to test this with git.exe built from (instrumented) source?

@mariuszkochanowski
Copy link
Author

I tried to dig further using output from my printf function inserts (in files sha1-file.c and files-backend.c) but i didn't find the cause of the problem. I tried to modify mingw.c file but it caused compilation errors.

@dscho
Copy link
Member

dscho commented Aug 27, 2020

@mariuszkochanowski after hours trying to get Docker to run in an Azure VM, I got this:

PS C:\Users\me\Desktop\GitIssue-b6afaa3157ad0cd34080b92f0d36571327f6c055> docker-compose -f docker-compose.yml build
Building git_for_windows_issue_2778
Step 1/8 : FROM mcr.microsoft.com/windows/servercore:2004
2004: Pulling from windows/servercore
ERROR: Service 'git_for_windows_issue_2778' failed to build: no matching manifest for windows/amd64 10.0.17763 in the manifest list entries

Any idea what is going wrong?

@mariuszkochanowski
Copy link
Author

I am using docker desktop on windows stable version (switched to windows containers):
You can download it from:
https://hub.docker.com/editions/community/docker-ce-desktop-windows/

In thread:
https://stackoverflow.com/questions/48066994/docker-no-matching-manifest-for-windows-amd64-in-the-manifest-list-entries
i found:
"In my case it was that the Windows OS version I was on did not support the tag"

You could try run it on image:

mcr.microsoft.com/windows/servercore:ltsc2019
or
mcr.microsoft.com/windows/nanoserver:1803-amd64

List of images:
https://hub.docker.com/_/microsoft-windows-servercore

@dscho
Copy link
Member

dscho commented Mar 10, 2022

Unfortunately, at some stage my Docker for Windows setup broke, and I never managed to get it back to work. And then this ticket got buried in my inbox.

@mariuszkochanowski are you still interested in this? I could walk you through building Git, patching it to include tons of debug messages, and then using it in a Docker container via a mapped volume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants