Global config cannot be set if ~/.gitconfig does not exist yet
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
When there is no ~/.gitconfig, the following code snippet
import pygit2
global_config = pygit2.Config.get_global_config() # ← Exception raised here
global_config['user.email'] = 'me@example.org'
fails with
Traceback (most recent call last):
File "global_config.py", line 2, in <module>
global_config = pygit2.Config.get_global_config()
File "/usr/lib/python3/dist-packages/pygit2/config.py", line 281, in get_global_config
return Config._from_found_config(C.git_config_find_global)
File "/usr/lib/python3/dist-packages/pygit2/config.py", line 265, in _from_found_config
check_error(err, True)
File "/usr/lib/python3/dist-packages/pygit2/errors.py", line 53, in check_error
raise IOError(message)
OSError: the global file '.gitconfig' doesn't exist: No such file or directory
I.e.,
- there seems to be no way of setting a global option unless
~/.gitconfigalready exists. - There seems to be no way to create the global config file ahead of time, at least not in a portable way (I doubt it is in
~/.gitconfigon Windows systems).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Python snippet with no ~/.gitconfig, then inspect pygit2/config.py, especially Config.get_global_config and _from_found_config. The fix is done when a global option can be set without an existing global config file, including on platforms where its location differs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100