pre-commit / pre-commit Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
This comment has been minimized.
This comment has been minimized.
@billsioros off topic |
@asottile Sorry for being off topic. This was the most relevant issue that I was able to find. Should I maybe open a separate issue? |
unless your issue is identical to the issue you should always make a new issue -- otherwise it's off topic |
When using
gitlint
as acommit-msg
hook 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 commit
for 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
gitlint
alone.The text was updated successfully, but these errors were encountered: