Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Handle pre-commit hook failures better as to not lose commit messages #584

Open
xenithorb opened this issue Dec 31, 2016 · 4 comments
Open
Labels

Comments

@xenithorb
Copy link

This is not an enhancement, but a bug.

Currently, if you try and use git-plus with a repository that has a pre-configured git pre-commit hook, and you take the time to write out a nice long commit message, the message is completely lost if the pre-commit hook fails.

Steps to reproduce:

  1. Copy paste this stuff into bash to setup the test case:
    temp=$(mktemp -d) 
    git init "$temp"
    echo -e '#!/bin/bash\necho "ERROR: Simulating failed pre-commit hook"\nexit 1' > "$temp/.git/hooks/pre-commit"
    chmod +x "$temp/.git/hooks/pre-commit"
    touch "$temp/foo"
    atom "$temp/foo"
  2. Now type some stuff in atom, and hit CTRL+s to save
  3. Now type CTRL+SHIFT+A a to "Git add all and commit"
  4. Add a commit message to the newly minted COMMIT_EDITMSG pane
  5. Finally, press CTRL+s again to save the message (pane disappears)
  6. Observe the failure and how the commit 1. fails 2. message is not retained anywhere

The way git proper handles this on the commandline is by running the pre-commit hook before it asks for a message.

If you're like me and forget sometimes where you have pre-commit hooks in place, and you're like me and write out lengthy messages - this is a serious bug/annoyance to have to re-write everything you just worked hard to explain.

@akonwi
Copy link
Owner

akonwi commented Jan 3, 2017

Git will run the hook before asking for a message if no arguments are passed with git commit.

Commits are handled by the package by passing the file, in which you've written the commit message into, to the commit command in the shell with git commit --file path/to/COMMIT_EDITMSG. After everything finishes, regardless of success, the COMMIT_EDITMSG file gets deleted. Perhaps it is better to keep the file or cache the failed commit message so it is easily retrievable.

@akonwi akonwi added the bug label Jan 3, 2017
@akonwi akonwi closed this as completed in a7601a4 Jan 5, 2017
@akonwi akonwi reopened this Jan 5, 2017
@xenithorb
Copy link
Author

This seems to have made it to 7.0.5, though Is see you left it open still. You're aware that this does not pass the test case?

@akonwi
Copy link
Owner

akonwi commented Jan 5, 2017

I typo'd and entered the wrong issue number in that commit message. Those changes were not related to this that's why I left it open

@xenithorb
Copy link
Author

I understand, no problem. I was just eager to test and a cursory look-over of the changeset seemed to imply a dialog. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants