Hadron / carthage-aws

AWS Plugin for Carthage
Other
2 stars 2 forks source link

Enhance the pre-commit hook to not allow unlinted files in on accident. #28

Closed fxdgear closed 8 months ago

fxdgear commented 8 months ago

Previously we had a situation that could occur which would allow for unlinted files to be commited if they previously failed the pre-commit hook then were corrected but not staged. This would effectivly allow an unlinted file to be commited.

This change will create a temp dir, and copy the files to the temp dir this way we only lint the files that have been staged. If it fails the temp dir is left intact so that it can be inspected by the user. Once it gets a successful run it'll clean itself up.

fxdgear commented 8 months ago

Why did you choose to use git show rather than the git checkout-index --prefix I recommended. This involves introducing an unnecessary loop for example.

SO I ran into an issue with checkout-index where it wasn't overwriting a file if it existed already, and then I missed the --force flag in the man page. Reverted to use --force so if the file changes multiple times... it'll get overwritten each time.

fxdgear commented 8 months ago

Please test on multiple changed files. I do not think $TMP_DIR/$files will append the directory to every file, just the first.

I fixed this, good catch! :)

fxdgear commented 8 months ago

.git is not always where the git root directory is. Consider the case where carthage_aws is embedded in a submodule or where git worktree is used.

I changed this to a pylint directory and then added it to the gitignore as well.