Bad config in `.gitconfig` causes wrong error in lazygit
Describe the bug
Bad config in .gitconfig would cause wrong error generation by lazygit
To Reproduce Steps to reproduce the behavior:
- mess up your
~/.gitconfig(in my case I had a typo ineditor) and save it - go to a git folder
- run
lazygitwhich throws this error:2022/07/11 09:25:57 Git version must be at least 2.0 (i.e. from 2014 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.
- in the same folder try
git statusand see this error:fatal: bad config line 15 in file /home/mehrad/.gitconfig
Expected behavior I expected that lazygit produces an error that points to the correct issue. imho the git error is clear enough and that can be used.
Screenshots Note that the error code of each command is printed at the end of the next prompt, so git's error code is 128 and lazygit is 1

Desktop (please complete the following information):
- OS: Manjaro Linux
- Lazygit Version:
commit=v0.34, build date=2022-04-27T13:28:28Z, build source=binaryRelease, version=0.34, os=linux, arch=amd64from the "community repo"
Additional context -- not applicable --
Yeah, currently we throw the same error for whatever git errors out with:
// if we get an error anywhere here we'll show the same status
minVersionError := errors.New(app.Tr.MinGitVersionError)
@jesseduffield should we just print out git's error here actually? And the version validation could be done in the same pass, we'd just need to match git version \d.\d+.\d+?
Yep if we get an actual error back from git we should just surface that. If we don't get an error back, then I'd parse the output for the version
@mmahmoudian would you be interested in fixing this issue? It's okay to say no, don't worry :)
@mmahmoudian would you be interested in fixing this issue? It's okay to say no, don't worry :)
I've never done anything in Go. Unless you are really ready to deal with and accept a PR from an absolute Go n00b.
I've never done anything in Go. Unless you are really ready to deal with and accept a PR from an absolute Go n00b.
Sure! We all gotta start somewhere, what better place to start than lazygit :)
I appreciate the leap of faith you are willing to take 🍻 . Then please assign it to me and I'll do my best.
I think I have to back out of this task as I cannot deliver in timely manner due to lack of enough Go knowledge and also busy schedule. I just add some info here for whoever wants to move forward:
How to reproduce the issue:
There might be many ways to corrupt your ~/.gitconfig, but the one I found the easiest is to open it in [n]vim, navigate to the middle of the name of an item (e.g editor), go to Insert mode (by pressing i), then insert a zero-byte character there by pressing CtrlV and then zero multiple times.
The best approach imo to address this:
imho the best way to approach this is to have a function to check the git viability, something like the following:
func initialGitCheck () error {
output, err := app.OSCommand.Cmd.New("git --version").RunWithOutput()
if err == nil {
return nil
} else {
return err
}
}
Then it should be called at the beginning of isGitVersionValid function to handle the issues with git first, and then move forward. After this, the validateGitVersion should be either removed or merged as part of it is redundant.