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.