Skip to content

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

Open
@jaredmcateer

Description

@jaredmcateer

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.

Activity

DaRacci

DaRacci commented on Mar 5, 2025

@DaRacci

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

extrawurst

extrawurst commented on Mar 5, 2025

@extrawurst
Collaborator

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

linked a pull request that will close this issue on Mar 5, 2025
jaredmcateer

jaredmcateer commented on Mar 5, 2025

@jaredmcateer
Author

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.

DaRacci

DaRacci commented on Mar 13, 2025

@DaRacci

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?

jaredmcateer

jaredmcateer commented on Mar 14, 2025

@jaredmcateer
Author

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.

lazygit.webm
DaRacci

DaRacci commented on Mar 15, 2025

@DaRacci

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @extrawurst@jaredmcateer@DaRacci

      Issue actions

        Program hangs if repo uses prepare-commit-hook that requires user input · Issue #2546 · gitui-org/gitui