-
Notifications
You must be signed in to change notification settings - Fork 280
Closed
Labels
Description
Running pre-commit hooks when amending a commit currently behaves a little strangely in that only the changes being added to the commit (not all changes in the commit) are checked by Overcommit.
This sometimes results in weird behavior where depending on the order you add files and amend them to a commit you can get around certain pre-commit hooks. For example, with Rubocop's MethodLength cop set to 20 lines, if you add a method that is 19 lines long, commit it, then amend the commit to add another couple of lines to the method body, the Rubocop lint message will now become a warning because it is reported on a line that is not currently staged, since it's already in the commit.
Benefits
- Prevents potential bugs/problems being introduced due to order of changes being amended
- Assuming we can detect when a pre-commit hook is being executed as part of an "amend", this allows us to write a hook that prevents amending commits on certain branches (e.g.
master) to enforce certain workflows
Costs
- Unclear if there is a definitive way to detect an amend on pre-commit (if it requires a non-reliable hack, this feature may be dead in the water)
- Significant behavior change, which may be surprising to existing users
Feel free to comment or ask questions in this issue.