Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Passing configuration parameter (git -c or git --config-env=) - set_persistent_git_options() (mostly) works #1604

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

Closed
linde12 opened this issue Jul 6, 2023 · 4 comments

Comments

@linde12
Copy link

linde12 commented Jul 6, 2023

Hi!

I want to override system wide and global git configs for all commands i'm running in this repo in order to set credential.helper to nothing (dont cache or use system store to save my passwords)

This can be done with git like so:

git -c credential.helper="" fetch

but, if possible, i'd like to use gitpythons Repo to fetch my do my fetching, but i can't find a way to pass the -c flag to git itself and not git-fetch. E.g. doing the following doesn't work because the flag is passed to git-fetch:

repo = Repo.init(path)
remote = repo.create_head(...)
...
remote.fetch(ref, c=\credential.helper=""')

because that essentially does:

git fetch -c credential.helper=""

but git-fetch doesn't know about any -c flag, only git does.

Is this even possible with gitpython? Thanks!

@linde12 linde12 changed the title Passing configuration parameter (git -c or git --config-env= Passing configuration parameter (git -c or git --config-env=) Jul 6, 2023
@linde12
Copy link
Author

linde12 commented Jul 6, 2023

I see Repo.clone has multi_options, but i want to use these set config-env for git-fetch too

@linde12
Copy link
Author

linde12 commented Jul 6, 2023

A colleague suggested set_persistent_git_options and it does indeed seem like what i want, but it does not work with submodules :-/

e.g.

repo = Repo(..)
remote = repo.create_head(...)
remote.fetch(ref) # OK my `-c core.askpass=...` works here
...
for submodule in repo.submodules:
  submodule.update(...) # not OK

is it clashing with clone_multi_options perhpas?

@Byron
Copy link
Member

Byron commented Jul 6, 2023

Thanks for reporting and sharing the workaround.

Maybe submodules have their own copy of the git command which is why it isn't present there? If so, is there a way to use set_persistent_git_options on each submodule?

Of course, this might be a genuine bug, especially related to submodules everything is possible.

@Byron Byron changed the title Passing configuration parameter (git -c or git --config-env=) Passing configuration parameter (git -c or git --config-env=) - set_persistent_git_options() works Jul 6, 2023
@Byron Byron changed the title Passing configuration parameter (git -c or git --config-env=) - set_persistent_git_options() works Passing configuration parameter (git -c or git --config-env=) - set_persistent_git_options() (mostly) works Jul 6, 2023
@linde12
Copy link
Author

linde12 commented Jul 6, 2023

@Byron

Thanks for the quick response!

Yeah this is what i thought as well, that submodules dont share the same git instance with the repo.

I didn't find a way to call set_persistent_git_options for a submodule, alas i didn't dig too deep. For now i reverted to using git.execute and passing the flags myself, but id rather use the Repo construct if at all possible 😃

@gitpython-developers gitpython-developers locked and limited conversation to collaborators Sep 7, 2023
@Byron Byron converted this issue into discussion #1649 Sep 7, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

2 participants