gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Program hangs if repo uses prepare-commit-hook that requires user input

Open jaredmcateer opened this issue 8 months ago • 6 comments
trafficstars

Describe the bug If a repo implements a prepare-commit-msg which requires user input gitui will hang on various operations that trigger the hook (commit, rebase, merge, cherry pick).

This is a pretty common pattern in repos using commitizen as one of the options that the project recommends is using prepare-commit-msg

To Reproduce

minimal example here: https://github.com/jaredmcateer/cz-gitui

Steps to reproduce the behavior:

  1. Open repo with prepare-commit-msg that requires user input
  2. Add/Modify a file
  3. Stage file
  4. Go to 'staged change' in gitui
  5. Press 'c'
  6. Observe gitui is unresponsive

Screenshots

In your processes you will see something like this: Image

Context (please complete the following information):

  • OS/Distro + Version: tested on Mac OS Sonoma 14.7.1 & Pop_OS! 22.0.4 LTS
  • GitUI Version: gitui nightly 2025-03-04 ()
  • Rust version: rustc 1.82.0 (f6e511eec 2024-10-15)

Additional context Lazygit also suffers from this, and the current workaround is to override all the commit-like commands with custom keybindings to disable Husky, but that will also kill other useful things like pre-commit hooks that run tests/linters.

jaredmcateer avatar Mar 04 '25 21:03 jaredmcateer

this sounds like a near impossible issue to fix, the easy solution might be adding a timeout to the command invocation.

DaRacci avatar Mar 05 '25 04:03 DaRacci

@DaRacci i agree that is what we should do here. interested in giving this a go?

extrawurst avatar Mar 05 '25 08:03 extrawurst

FWIW I found lazygit allows committing via the system editor with shift+c which does allow gracefully handling the hook, but they have no functionality for the other commands that trigger the prepare-commit-msg hook and cause it to hang as well. You can also build custom menu/commands that run in a subprocess that other users are reporting works for them but I haven't dug into that.

I understand if this is too much work. I tend to agree with the sentiment that what commitizen is doing is going against the spirit of git hooks. I just happen to work on a lot of repos that aren't mine with it and having my TUI frozen trying to do something like a rebase drives me a bit batty, so at least having a timeout is better than having to kill the process and reset my terminal.

jaredmcateer avatar Mar 05 '25 16:03 jaredmcateer

FWIW I found lazygit allows committing via the system editor with shift+c which does allow gracefully handling the hook, but they have no functionality for the other commands that trigger the prepare-commit-msg hook and cause it to hang as well. You can also build custom menu/commands that run in a subprocess that other users are reporting works for them but I haven't dug into that.

I understand if this is too much work. I tend to agree with the sentiment that what commitizen is doing is going against the spirit of git hooks. I just happen to work on a lot of repos that aren't mine with it and having my TUI frozen trying to do something like a rebase drives me a bit batty, so at least having a timeout is better than having to kill the process and reset my terminal.

how does using the system editor allow these hooks to work, i may not quite be following could you record a clip of how this functions?

DaRacci avatar Mar 13 '25 23:03 DaRacci

Yea sure. Sorry I'm on wayland and I haven't quite figured out how to get something going that shows my key presses in screencasts but basically I stage the file, press shift+c it switches the the terminal where I can follow commitizens prompts, it then drops me into my $EDITOR (nvim) to make any additional changes and then :wq to save and commit, then I'm back in the terminal and when I press any button I'm brought back into lazygit.

https://github.com/user-attachments/assets/5c819625-9a5b-4149-96ef-5898ceb4201f

jaredmcateer avatar Mar 14 '25 20:03 jaredmcateer

Thanks for the demo, I was hoping this would give a lead but it seems like its just dropping you into a shell where git commit has been ran.

DaRacci avatar Mar 15 '25 05:03 DaRacci