git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Bug: ls-remote refuses to run when work tree mounted in container

From
CDCristian Dinu <cristian.virgil.dinu@gmail.com>
Date
Sep 2, 2025, 17:50 UTC
Message-ID
<6be0928c-df10-417e-a264-f4562f9d2585@gmail.com>
First of all hello,
I think I found a bug in git, 'git ls-remote', to be more specific.

My workflow on my current project consists of using git work trees and testing the work I do in a podman container. My project is an Ansible playbook meant to automate different things. One of those things is doing some git clones.

Ansible module 'ansible.buildin.git' makes use of 'git ls-remote' to obtain some information about the git repository I want to clone:

This is what the Ansible module executed behind the scenes:

''' git ls-remote http://some.repo.com -h refs/head/master '''

The problem I'm facing has to do with 'git ls-remote' requiring you to run it in a git repository or in no git repository, but something in the middle makes the tool blow up.

Here are the exact repo steps so you can reproduce and better understand the issue I'm facing:

1. 'mkdir -p /tmp/git_ls_remote_bug'
2. 'cd /tmp/git_ls_remote_bug'
3. 'git clone --bare https://github.com/git/git.git .bare/'
4. 'echo "gitdir: .bare/" > .git'
5. 'git worktree add master'
6. 'cat master/.git'
    Should output 'gitdir: /tmp/git_ls_remote_bug/.bare/worktrees/master'
7. 'podman run -it --rm -v "./master/:/workdir:ro,Z" fedora:42'
The next steps are executed in the container:
8. 'dnf install -y git'
9. 'cd /workdir'
10. 'git ls-remote https://github.com/tmux-plugins/tpm -h refs/heads/master'
Will return:

''' fatal: not a git repository: /tmp/git_ls_remote_bug/.bare/worktrees/master '''

This is the bug I want to point out, even if I did a 'git ls-remote' on a remote repository 'git' or maybe 'git ls-remote' in particular wants to be executed in a git repository.

I want to add the following, if I do 'cat /workdir/.git' inside the container it will show 'gitdir: /tmp/git_ls_remote_bug/.bare/worktrees/master' and because that is not present in the container at all it thinks it should not run.

I did not explore git's code to see if I can do a patch, but from a user's point of view I think 'git ls-remote' should skip the 'Am I in a git repository?' check and just query the remote repository when a remote repository is provided as argument.

At the moment of writing I used git 2.51.0 both on the host and in the container.

~ Cristian
PS: It's the first time I write to a mailing list, if I did a mistake 
tell me so I
     can learn.
Message 1 of 1 in “Bug: ls-remote refuses to run when work tree mounted in container”
  1. Cristian DinuSep 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.