rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.68k stars 385 forks source link

Repostory::open failing due to keys it doesn't understand in `.gitconfig` #844

Closed yaahc closed 2 years ago

yaahc commented 2 years ago

I ran into this when trying to run https://github.com/nabijaczleweli/cargo-update

When I ran the command I got the following error, though originally it didn't include the source error from git2 in the output, so the git2 part of the error was from me editing their source before rerunning it:

Failed to open registry repository at /home/jlusby/.cargo/registry/index/github.com-1ecc6299db9ec823.: failed to parse config file: invalid configuration key (in /home/jlusby/.gitconfig:28); class=Config (7)

My .gitconfig contains the following keys (after fixing it):

# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
    name = Jane Lusby
    email = jlusby@yaah.dev
[commit]
    verbose = true
[alias]
    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lglocal = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --branches
    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
    lg3 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
    lg = !"git lglocal"
[core]
    excludesFile = ~/.gitignore_global
    pager = delta
[rebase]
    autosquash = true
[diff]
    colorMoved = default
[delta]
    navigate = true
    line-numbers = true
    side-by-side = true
    ; map-styles = \
    ;    bold purple => syntax "#330f29", \
    ;    bold blue => syntax "#271344", \
    ;    bold cyan => syntax "#0d3531", \
    ;    bold yellow => syntax "#222f14"

The map-styles entry is what broke it. Commenting it out fixed the error. These keys are used by https://github.com/dandavison/delta for --color-moved support and were copied from https://github.com/dandavison/delta/blob/master/themes.gitconfig#L279-L283. I don't think I did this the standard or proper way but it was the only way I managed to get that color-moved stuff to work. Feel free to close this if you think it's an issue with my delta config rather than git2 and I'll move it to their repo.

ehuss commented 2 years ago

cargo-update appears to be using version 0.11 of git which is several years old. I believe this was fixed a long time ago, so I'm going to close. If you can reproduce with the latest version of git2, feel free to reopen.