Ensure pre-commit hook scans staged files #13
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit updates the pre-commit hook to scan staged files instead of files in the working directory.
This ensures that if a staged file was invalid, then the working directory version of the file was fixed, that the
--scan
command will still detect the error in the staged file rather than thinking the problem is fixed due to the modified working directory file. See here for the added test case.In order to achieve this, I introduced the
--cached
option to scan. This matches the--cached
option fromgit grep
. I also added--no-index
and--untracked
. With the addition of these changes, I added more validation to the provided arguments of the tool to ensure that the user only supplies arguments related to the subcommand they are running, and that mutually exclusive arguments are not present. For example,--recursive
cannot be used alongside--cached
because--recursive
is only relevant when working with files outside of the git repository.Closes #12
@trevorrowe @jamesls @jeskew