lazygit do not support git pre commit
Hello there! I recently find that lazygit has no support for the git pre commit.
Case 1
when I write the git commit message and press down the Enter,lazygit will wait a moment (depends on what the git pre commit script) .And I can not see my script output in the terminal.
Case 2
when my git pre commit script has an error, lazygit will crash and finally get the panic log.
the panic log is here:
panic: exit status 1
goroutine 1 [running]:
main.handleCommitPress.func1(0xc420134000, 0xc420478000, 0xc420136060, 0xc420136060)
$GOPATH/src/github.com/jesseduffield/lazygit/files_panel.go:167 +0xea
main.wrappedConfirmationFunction.func1(0xc420134000, 0xc420478000, 0xc, 0xc420041e01)
$GOPATH/src/github.com/jesseduffield/lazygit/confirmation_panel.go:19 +0x6e
github.com/jesseduffield/gocui.(*Gui).execKeybindings(0xc420134000, 0xc420478000, 0xc420041da0, 0x10d21b9, 0x0, 0x0)
$GOPATH/src/github.com/jesseduffield/gocui/gui.go:659 +0xdd
github.com/jesseduffield/gocui.(*Gui).onKey(0xc420134000, 0xc420041da0, 0xc4200e0200, 0xc42013e000)
$GOPATH/src/github.com/jesseduffield/gocui/gui.go:623 +0x1b3
github.com/jesseduffield/gocui.(*Gui).handleEvent(0xc420134000, 0xc420041da0, 0xc420041d98, 0x0)
$GOPATH/src/github.com/jesseduffield/gocui/gui.go:428 +0x40
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc420134000, 0x0, 0x0)
$GOPATH/src/github.com/jesseduffield/gocui/gui.go:388 +0x2c0
main.run()
$GOPATH/src/github.com/jesseduffield/lazygit/gui.go:347 +0x175
main.main()
$GOPATH/src/github.com/jesseduffield/lazygit/main.go:68 +0xf2
Proposal
we can pop up a window (just like the git commit window) to show git pre commit output after we enter the git commit message.
if there is an error in git pre commit script, we should rollback this commit and stay in lazygit's terminal as well.
if this proposal is acceptable, I can do something and send U a PR.
yep that sounds good to me! If you can find a way to have the ouput get read into a popup panel as it goes, that would be awesome cos there are other places we can utilise the same logic
@jesseduffield Since lazygit removed the pure go commands and use go-git for the most git operations , the git commitwill skip the git pre commit script .So, I can not get the std output now.And I checked the go-git Commit function, it seems like it does not support the git hooks.
we perhaps should check if there is a .git/hooks/pre-commit or not ,if so, we call the pure go command to do the commit ,otherwise, use go-git( I know this is not a graceful solution at all ).
The go-git issue is here https://github.com/src-d/go-git/issues/913
Damn. I wanted go-git to be the answer to platform independence and having to do less guesswork parsing the string output of the cli git commands but im starting to think that go-git doesnt really have all the functionality we need. I suppose when it works perfectly we should use it but otherwise we may as well just use the direct CLI and iron out whatever kinks show up. I might need to over the docs more closely but yeah
I've reverted to using the CLI command in https://github.com/jesseduffield/lazygit/commit/4cd2d7065993a8dfbb0f933177b128990f699e28
The both solutions have advantages and disadvantages,I think we should keep a other branch to wait for the support of go-git ,and I will continue to work on the CLI command solution XD
The WIP PR is here: #296
The final solution, at my code implement, is to provide a streaming git commit message panel to trace the git pre commit output whether it passes the pre commit script or not.
Are people still actively looking into this?
The main limitation currently is that a pre commit command can be any program and often it spits out random terminal characters telling the cursor to move to different positions, rewrite old characters in the case of a loader, etc. It would take a bit of work to support all those characters. I made some headway on this problem in lazynpm, but haven't found the time to port across those changes to this project. Another thing is that the pre-commit may want to receive input from the user, which we'd need to work out.
In the meantime, doing shift+C to initiate a commit should run the pre-commit, but it's admittedly not as cool as it being done from within lazygit.
a pre commit command can be any program and often it spits out random terminal characters telling the cursor to move to different positions, rewrite old characters in the case of a loader, etc. It would take a bit of work to support all those characters.
@jesseduffield Could Lazygit be updated to ensure that the original proposal is implemented if any hook returns a non-zero exit code? This would mean that the process (commit, push, etc.) would only continue if all hooks return an exit code of 0.