In a non-interactive environment, git commit doesn't work
See original GitHub issueIn a non-interactive git environment (like Visual Studio Code), the git hook hangs while waiting for input from the user.
I’ve installed gitlint v0.15.0 on OpenSuse in WSL and added it to my repo using install-hook with a default config file using generate-config. However, if I want to commit in Visual Studio Code (using the Remote - WSL extension), the commit process hangs if there’s something wrong with my commit message. The only way to proceed is by killing the script
The output
> gitlint --staged --msg-filename "$1" run-hook
> git config --get-all user.name
> git config --get-all user.email
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
> git ls-files --stage -- /home/phillip/src/100-days-of-code/.gitlint
> git cat-file -s 317c4136f08cafaeb8f577a043aa4291684e6424
> git show --textconv :.gitlint
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] .git/hooks/commit-msg: line 22: 5628 Terminated
I hoped that adding --silent and --ignore-stdin to the commit hook would help but unfortunately it did not.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
git-commit Documentation - Git
The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point...
Read more >How do I run git rebase --interactive in non-interactive manner?
This command will run sed on file provided by git rebase -i . It will change the line pick 134567 into e 1234567...
Read more >GitLab Runner commands
Executing gitlab-runner register adds a new configuration entry. It doesn't remove the previous ones. There are two options to register a runner: interactive....
Read more >Ubuntu Manpage: git-commit - Record changes to the repository
by listing files as arguments to the commit command (without --interactive or --patch switch), in which case the commit will ignore changes staged...
Read more >Source Control with Git in Visual Studio Code
VS Code as Git editor · Make sure you can run code --help from the command line and you get help. if you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, most obvious question first (just so we can rule it out): did you actually try to answer the question (y/n/e), or is the prompt not interactive at all?
Secondly, I think our focus on the
--ignore-stdin
might be taking us in the wrong direction, although the confusion is understandable.We’re conflating gitlint’s
--ignore-stdin
general option with enabling/disabling the interactive gitlint commit-msg hook prompt. Those are 2 different things, although both have to do with stdin and TTYs.Consider these examples of
--ignore-stdin
:Normally, Python’s
input()
is what causes the abort to happen if stdin is non-interactive. But clearly that’s not happening in your case (i.e. why I asked whether it’s definitely not possible to just answer y/n/e on the prompt in VSCode). https://github.com/jorisroovers/gitlint/blob/e06dfe02c222b1d4807c17b9c534d7deeed7a8e6/gitlint/cli.py#L386Ideally, we should be able to detect this scenario reliably, but from experience I know that introducing a ‘force ignore’ option is not a bad idea so we always have a work-around. However, if we do this, I think it should be an option specific to
run-hook
and not re-use the generic--ignore-stdin
option that already has a different meaning. Something like--non-interactive
:--non-interactive
could then also be set using a.gitlint
optionhook-non-interactive=True
and env varGITLINT_HOOK_NON_INTERACTIVE=1
.Of course, because it’s a force flagm it means the hook will always be non-interactive, even when you invoke it from a regular CLI.
PS: christmas time 🎄 , so delayed responses are very likely. I suggest not spending/wasting too much time on PRs on this until we’ve figured out the approach first. Thanks for your help!
I came up with custom
commit-msg
git hook like this