jesseduffield / lazygit

simple terminal UI for git commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashing on negative fetch refspecs

lukaspiatkowski opened this issue · comments

Describe the bug
Lazygit crashes when opening a git repository containing negative refspec in a fetch option inside .git/config.

To Reproduce
Steps to reproduce the behavior:

  1. Clone a repository (e.g. gh repo clone jesseduffield/lazygit)
  2. Open .git/config
  3. Add a negative refspec in a fetch option under a [remote ...] section, e.g.:
[remote "origin"]
        url = git@github.com:jesseduffield/lazygit.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = ^refs/heads/private/*
  1. Open lazygit inside this repo and see it crashing

Expected behavior
Lazygit should operate as usuall and should respect the negative refspec (e.g. without Lazygit if you git fetch the branches mentioned by negative refspec will be ignored)

Screenshots
Screenshot 2022-05-26 at 13 39 17

Errors are non-deterministic, once I was able to catch "malformed refspec, separators are wrong":

Screenshot 2022-05-26 at 13 50 31

Desktop (please complete the following information):

  • OS: MacOs Monterey (Apple Silicon)
  • Lazygit Version v0.34
  • lg --version: commit=, build date=, build source=homebrew, version=0.34, os=darwin, arch=arm64

Additional context
The stderror message changes after few attempts of running Lazygit in the same terminal:

  1. panic: fork/exec /opt/homebrew/bin/git: too many open files (full output)
  2. panic: pipe: too many open files (full output)
  3. panic: open /dev/null: too many open files (full output)
    It is also hard to catch the screenshot attached above, because lazygit usually clears the screen after this error, but from time to time after few attempts the terminal is so broken that lazygit doesn't clear the screen and other rendering errors happen.

I've tried this with git.autoFetch = false in my ~/.config/lazygit/config.yml, but that didn't help.

Good catch, is this something that stops you from using lazygit or did you just notice it by accident?

I.e. if it's a priority, I can take a look at it today. Would you maybe be willing to give it a try?

I've caught it when trying to use negative refspecs to filter out branches that Github's Merge Queue leaves behind on the main branch. I would say it blocks me from using negative refspecs more than it blocks me from using lazygit for now, but I wanted to merge the negative refspecs for my organization to benefit, so it would be nice to get this sorted sooner rather than later :).

I've tried to quickly fix it now, but I don't know GO and the problem seems to originate in go-git, so I don't know if I am doing the right things here. I've managed to patch it up with this commit and it seems to work, but ./test.sh seems to be stuck (EDIT: it finished just now):

$❯ ./test.sh
ok  	github.com/jesseduffield/lazygit/pkg/tasks	0.329s	coverage: 58.4% of statements
ok  	github.com/jesseduffield/lazygit/pkg/app	0.218s	coverage: 8.2% of statements
?   	github.com/jesseduffield/lazygit/pkg/app/daemon	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/test	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/config	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/integration	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/constants	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/utils	0.232s	coverage: 44.8% of statements
?   	github.com/jesseduffield/lazygit/pkg/updates	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/env	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/common	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/logs	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/theme	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/gui	270.580s	coverage: 0.0% of statements
?   	github.com/jesseduffield/lazygit/pkg/gui/popup	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/gui/filetree	0.374s	coverage: 31.7% of statements
?   	github.com/jesseduffield/lazygit/pkg/gui/types	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/context	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/context/traits	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/keybindings	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/modes/filtering	[no test files]
?   	github.com/jesseduffield/lazygit/pkg/gui/modes/diffing	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/gui/lbl	0.223s	coverage: 24.5% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/style	0.241s	coverage: 91.7% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/boxlayout	0.220s	coverage: 100.0% of statements
?   	github.com/jesseduffield/lazygit/pkg/gui/controllers	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers	0.234s	coverage: 1.7% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts	0.225s	coverage: 23.0% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/presentation	0.236s	coverage: 44.6% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/presentation/authors	0.434s	coverage: 25.6% of statements
ok  	github.com/jesseduffield/lazygit/pkg/gui/presentation/graph	0.251s	coverage: 89.7% of statements
?   	github.com/jesseduffield/lazygit/pkg/gui/presentation/icons	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/gui/services/custom_commands	0.255s	coverage: 21.3% of statements
?   	github.com/jesseduffield/lazygit/pkg/secureexec	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/commands	0.237s	coverage: 77.3% of statements
?   	github.com/jesseduffield/lazygit/pkg/commands/types/enums	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/commands/hosting_service	0.250s	coverage: 85.5% of statements
?   	github.com/jesseduffield/lazygit/pkg/commands/models	[no test files]
ok  	github.com/jesseduffield/lazygit/pkg/commands/git_config	0.218s	coverage: 37.3% of statements
ok  	github.com/jesseduffield/lazygit/pkg/commands/patch	0.236s	coverage: 36.1% of statements
ok  	github.com/jesseduffield/lazygit/pkg/commands/git_commands	0.274s	coverage: 29.2% of statements
ok  	github.com/jesseduffield/lazygit/pkg/commands/loaders	0.275s	coverage: 42.0% of statements
ok  	github.com/jesseduffield/lazygit/pkg/commands/oscommands	0.260s	coverage: 13.4% of statements
ok  	github.com/jesseduffield/lazygit/pkg/i18n	0.217s	coverage: 13.6% of statements
ok  	github.com/jesseduffield/lazygit/pkg/cheatsheet	0.220s	coverage: 26.0% of statements
?   	github.com/jesseduffield/lazygit/test/runner	[no test files]
?   	github.com/jesseduffield/lazygit/test/lazyintegration	[no test files]

I will leave it to you to decide if this PR should go to go-git or jesseduffield's fork and what to do with it.

I forgot to mention it here, but I've created this PR: jesseduffield/go-git#1

ezoic increase your site revenue