gitext-rs / git-stack

Stacked branch management for Git
Apache License 2.0
512 stars 19 forks source link

Unable to register aliases if XDG config doesn't exist #284

Closed bemyak closed 1 year ago

bemyak commented 1 year ago

Please complete the following tasks

Description

On Linux, git-stack fails to register aliases if $XDG_CONFIG_HOME/git/config doesn't exist.

This is caused by this code, which requests XDG-level config specifically. The git2 docs for Config::open_global say:

XDG file shouldn’t be used unless the use has created it explicitly. With this function you’ll open the correct one to write to.

So, I believe we should switch from open_level(git2::ConfigLevel::XDG) to open_global when opening the config.

An alternative fix would be to ensure that the file exists in the first place.

Version

0.10.9

Steps to reproduce

On Linux, ensure that $XDG_CONFIG_HOME/git/config doesn't exist:

mv $XDG_CONFIG_HOME/git/config $XDG_CONFIG_HOME/git/config.bak

Try registering the aliases:

git-stack alias --register

Actual Behaviour

An error occurs:

no configuration exists for the given level '3'; class=Config (7); code=NotFound (-3)

Expected Behaviour

The aliases are registered in ~/.gitconfig

Debug Output

$ git-stack alias -vv --register                                                                                                                                                         
no configuration exists for the given level '3'; class=Config (7); code=NotFound (-3)