{"thread":{"id":"64074","subject":"Bug: ls-remote refuses to run when work tree mounted in container","startedAt":"2025-09-02T17:50:18Z","lastAt":"2025-09-02T17:50:18Z","messageCount":1,"participants":["Cristian Dinu"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"525362","messageId":"6be0928c-df10-417e-a264-f4562f9d2585@gmail.com","threadId":"64074","inReplyTo":null,"subject":"Bug: ls-remote refuses to run when work tree mounted in container","fromName":"Cristian Dinu","fromEmail":"cristian.virgil.dinu@gmail.com","sentAt":"2025-09-02T17:50:14Z","receivedAt":"2025-09-02T17:50:18Z","isPatch":false,"sender":{"key":"cristian.virgil.dinu@gmail.com","avatar":null},"body":"First of all hello,\n\nI think I found a bug in git, 'git ls-remote', to be more specific.\n\nMy workflow on my current project consists of using git work trees and \ntesting\nthe work I do in a podman container. My project is an Ansible playbook \nmeant to\nautomate different things. One of those things is doing some git clones.\n\nAnsible module 'ansible.buildin.git' makes use of 'git ls-remote' to obtain\nsome information about the git repository I want to clone:\n\nThis is what the Ansible module executed behind the scenes:\n\n'''\ngit ls-remote http://some.repo.com -h refs/head/master\n'''\n\nThe problem I'm facing has to do with 'git ls-remote' requiring you to \nrun it\nin a git repository or in no git repository, but something in the middle \nmakes\nthe tool blow up.\n\nHere are the exact repo steps so you can reproduce and better understand the\nissue I'm facing:\n\n1. 'mkdir -p /tmp/git_ls_remote_bug'\n\n2. 'cd /tmp/git_ls_remote_bug'\n\n3. 'git clone --bare https://github.com/git/git.git .bare/'\n\n4. 'echo \"gitdir: .bare/\" > .git'\n\n5. 'git worktree add master'\n\n6. 'cat master/.git'\n    Should output 'gitdir: /tmp/git_ls_remote_bug/.bare/worktrees/master'\n\n7. 'podman run -it --rm -v \"./master/:/workdir:ro,Z\" fedora:42'\n\n\nThe next steps are executed in the container:\n\n8. 'dnf install -y git'\n\n9. 'cd /workdir'\n\n10. 'git ls-remote https://github.com/tmux-plugins/tpm -h refs/heads/master'\n\n\nWill return:\n\n'''\nfatal: not a git repository: /tmp/git_ls_remote_bug/.bare/worktrees/master\n'''\n\nThis is the bug I want to point out, even if I did a 'git ls-remote' on \na remote\nrepository 'git' or maybe 'git ls-remote' in particular wants to be \nexecuted in a\ngit repository.\n\nI want to add the following, if I do 'cat /workdir/.git' inside the \ncontainer it\nwill show 'gitdir: /tmp/git_ls_remote_bug/.bare/worktrees/master' and \nbecause that\nis not present in the container at all it thinks it should not run.\n\nI did not explore git's code to see if I can do a patch, but from a \nuser's point of\nview I think 'git ls-remote' should skip the 'Am I in a git repository?' \ncheck and\njust query the remote repository when a remote repository is provided as \nargument.\n\nAt the moment of writing I used git 2.51.0 both on the host and in the \ncontainer.\n\n~ Cristian\n\nPS: It's the first time I write to a mailing list, if I did a mistake \ntell me so I\n     can learn.\n\n"}]}