How to get the user.email config using gitpython ?
Asked Answered
K

1

6

I have a repo initialized as

r = git.Repo.init(dirPath)

How can I get the user.email field for the git config for that repo using gitpython?

Kirschner answered 1/3, 2017 at 17:1 Comment(0)
K
12

After looking into the source of gitpython this is one way I managed to do it.

r = git.Repo.init(dirPath)
reader = r.config_reader()
field = reader.get_value("user","email")
Kirschner answered 5/3, 2017 at 19:39 Comment(4)
In case the user.email config does not exist, the get_value function may throw and exception or return a default value. The user can affect that behavior by passing a default parameter named "default" to the get_value function.Kirschner
How to do this without Repo object? Like getting global settings.Afflictive
That's not yet possible, see github.com/gitpython-developers/GitPython/issues/775Continuator
Quick update: To access global settings directly, you can now use git.config.GitConfigParser().get_value(...) (see github.com/gitpython-developers/GitPython/pull/950)Anabaptist

© 2022 - 2024 — McMap. All rights reserved.