Skip to content

Global config cannot be set if ~/.gitconfig does not exist yet #915

Open
@MarcelWaldvogel

Description

@MarcelWaldvogel

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'] = '[email protected]'

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.,

  1. there seems to be no way of setting a global option unless ~/.gitconfig already exists.
  2. 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 ~/.gitconfig on Windows systems).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions