Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
commit-msg hook with gitlint makes the text get lost on failure #833
Comments
|
I can't reproduce "IIRC, I didn't observe this issue with Here's my session:
I'm then presented with:
There's nothing particularly special about how |
|
You're right, it's the default |
|
Could be a neat little feature yeah! Need to be sure it plays nicely if someone defines their own |
|
Now that |
|
Here's a small demo of this idea, this can probably be cleaned up and turned into a .pre-commit-config.yamlrepos:
- repo: local
hooks:
- id: save-commit-msg
name: save commit message
entry: ./bin/save-commit-msg
verbose: true
language: script
stages: [commit-msg]
- id: restore-commit-msg
name: restore commit message
entry: ./bin/restore-commit-msg
verbose: true
language: script
stages: [prepare-commit-msg]
- id: derp
name: derp
entry: derp
language: fail
stages: [commit-msg]bin/restore-commit-msg#!/usr/bin/env python3
import os
import shutil
import sys
def main():
if os.path.exists('.git/pre-commit-saved-commit-msg'):
with open(sys.argv[1]) as f:
lines = [x for x in f if x.strip() if not x.startswith('#')]
if not lines:
print('restoring old commit message...')
shutil.copy('.git/pre-commit-saved-commit-msg', sys.argv[1])
if __name__ == '__main__':
exit(main())bin/save-commit-msg#!/usr/bin/env python3
import shutil
import sys
def main():
shutil.copy(sys.argv[1], '.git/pre-commit-saved-commit-msg')
if __name__ == '__main__':
exit(main()) |
|
It's a good start, lacking:
which I tried to solve, here's what I got so far (using e.g. Play with Docker):
The last amend will bring up the last rejected message as a comment in the new one. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

When using
gitlintas acommit-msghook withpre-commit, I run into issue of commit message getting lost easily when gitlint finds that it's not good enough.Repro: on a clean minimal debian 9.5.0, I run:
One can retrieve the text from .git/COMMIT_EDITMSG after the gitlint test, but once you hit
git commitfor the second time, all is lost. I'd expect that you get a second chance without risk of losing all your text.IIRC, I didn't observe this issue with
gitlintalone.