-
Notifications
You must be signed in to change notification settings - Fork 280
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
Detect git commit --amend
in pre-commit hooks so staged files include everything in commit
#146
Comments
Since no new commits have been created when the |
What happens if the user invoked
Luckily, we can easily see if an alias is defined using For aliases that invoke shell scripts, those scripts will still end up triggering their own pre-commit hook, e.g. for: [alias]
amend = "!f() { git commit --amend; }; f" ...running
...and so our original code for detecting amends will work just fine. |
Looks like shell aliases are expanded in the |
Seems like git aliases are also expanded. Using a dummy repository with the following pre-commit hook: #!/usr/bin/env bash
ps -ocommand= -p $PPID I get the following: $ git config alias.amd 'commit --amend'
$ git amd
/usr/local/bin/git commit --amend
[master 675d5e1] blargh
... |
Which OS are you running? On both CentOS 7 and Mac OS X 10.10.2 I get the following output using your script:
I've tested this with both bash |
Whoops, forgot that
|
Implemented in #167. Thanks! |
Without this check, we could not amend commits when the index was empty. The invocation of `ps' is from sds/overcommit#146 (comment).
Without this check, we could not amend commits when the index was empty. The invocation of `ps' is from sds/overcommit#146 (comment).
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
'sMethodLength
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, theRubocop
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
master
) to enforce certain workflowsCosts
Feel free to comment or ask questions in this issue.
The text was updated successfully, but these errors were encountered: