question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Commit msg not re-read after edit (using run-hook)

See original GitHub issue

Setup: gitlint as a commit-msg hook (installed using the install-hook command)

Repo steps:

  1. A commit msg violating the configured linting rules is used (e.g. git commit -m “This fails linting”)
  2. gitlint will report the problem(s) and ask the (y)es/(n)o/(e)dit question.
  3. edit is chosen, and the message is re-written in the editor (vim in my case). New message is know to pass linting.
  4. gitlint will report the same problem(s) as in step 2

Looking at the code, I think the problem is that the message file loaded (via --msg-filename) is kept open (reading position is reset to zero). It is not closed and re-opened after the edit. My guess is that on Linux, the editor will re-write the file (causing it to get a new inode) while gitlint (via Click) keeps a handle to the old file (old inode). Because the file reading position is just set to zero, the contents of the old file will get re-read after the edit is completed. (On Windows, this will most likely work because of different file system behavior).

The above behavior on Linux makes the current commit-msg hook implementation non-functional as the user will never be able to fix a linting error using the editor option.

I have reverted to the old (v. 0.10.0) hook implementation (which works fine for 0.15.0 also) as a work-around.

Otherwise: Thanks for a nice tool!

Br Lars Marqvart

Top output from gitlint --debug:

DEBUG: gitlint.cli To report issues, please visit https://github.com/jorisroovers/gitlint/issues
DEBUG: gitlint.cli Platform: Linux-5.4.0-65-generic-x86_64-with-glibc2.29
DEBUG: gitlint.cli Python version: 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0]
DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: git version 2.25.1
DEBUG: gitlint.cli Gitlint version: 0.15.0
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: [NOT SET]
DEBUG: gitlint.cli DEFAULT_ENCODING: UTF-8
DEBUG: gitlint.cli Configuration

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sigmavirus24commented, Mar 11, 2021

It was consistent then, I kept editing to see if I’d missed whitespace. I haven’t seen it since but I think that’s because I haven’t left a trailing whitespace in again. It’s my work-provided laptop it was happening on. I’ll double check today and provide debugging info if I can repro

0reactions
dbongartzcommented, Feb 22, 2022

Would love to have this working. I have it consistently under different Linux (Ubuntu, Manjaro) Systems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Choosing 'edit' when using the commit-msg hook on windows ...
When gitlint re-opens the editor (e.g. vim), there are some serious issues with the text editor. This is likely because of how gitlint...
Read more >
Commit message file missing in commit-msg hook
For some reason, when I make a commit, I get the following errors because $1 seems to be empty. cat: '': No such...
Read more >
gitlint - Bountysource
Commit msg not re-read after edit (using run-hook) $ 0 · A commit msg violating the configured linting rules is used (e.g. git...
Read more >
pre-commit
We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements....
Read more >
Commit message templates - GitLab Docs
Commit templates use syntax similar to the syntax for review suggestions. ... After you edit a commit message on an open merge request,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found