astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
23.62k stars 678 forks source link

Trying to use custom git-credentials location, appears to get ignored #8441

Open EdgyMeshx opened 3 hours ago

EdgyMeshx commented 3 hours ago

This is a follow on from #8413, I have a custom .gitconfig in a child directory that is picked up if I am editing a repo inside that child directory (effectively allowing me to commit etc under a user other than my default self.)

This works fine using git normally, but if I configure it to point to a custom .git-credentials file, it appears to go ignored by uv. I think this is somewhat expected behaviour as my custom .gitconfig is only picked up if you are in a subdirectory of the location of that custom config.

I am assuming that uv is running git from its own location not the cwd and this is causing custom configuration to be ignored. Is there any way to prevent this from happening, or any way this could be addressed (have uv pick up the cwd where it was executed and have that be the context its children commands like git run in?) as a part of uv.

Example configs ~/.gitconfig

[user]
    email = email@me.com
    name = Default User

[includeIf "gitdir:~/code/work/**"]
    path = ~/code/work/.gitconfig

~/code/work/.gitconfig

[user]
    email = email@work.com
    name = Work User

[credential]
    helper = store --file ~/code/work/.git-credentials

If I move the git credentials to home, uv picks them up just fine.

zanieb commented 2 hours ago

Hm, this seems challenging. We might need to copy the file into the build context? Or clone in the user's directory then move it into the cache? It's possible we'll need the config for future fetches though.

EdgyMeshx commented 1 hour ago

The issue with copying it is it can be in multiple pieces depending on current location. Currently we only go one repo deep so a single fetch would suffice, but if we ever did nest repos you are right, additional fetches could be needed.

If there is some way for the cwd to be the context uv runs against, so any file look ups start in the "correct" location and walk the tree upwards, I believe it would solve (at least my version) of the problem.

EdgyMeshx commented 1 hour ago

Have just tested and gitconfig does not honor relative paths, so the store file should be a full path if it was to be copied.

EdgyMeshx commented 36 minutes ago

To clarify, this isn't just a git-credentials issue, this would impact custom ssh keys in the same way

having this instead of credential in /code/work/.gitconfig is also lost by uv.

[core]
    sshCommand = "ssh -i ~/.ssh/id_work"

have updated issue title