Skip to content
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

Added two new options that allow for file modifications #1188

Closed
wants to merge 2 commits into from

Conversation

mmabey
Copy link

@mmabey mmabey commented Oct 24, 2019

This PR introduces two new options to pre-commit that do not change the program's default behavior, but allow users to either specify command-line options or set environment variables to do two things:

  1. --modified-files-ok / PRE_COMMIT_MODIFIED_FILES_OK: When specified/set, pre-commit no longer classifies it as a failure when hooks have a non-zero exit status or when hooks modify files (the former is required to accommodate the latter). What this means in practice is that when pre-commit is invoked from a git commit command, it will not prevent the commit from proceeding if a hook modifies a file.

  2. --add-modified-files / PRE_COMMIT_ADD_MODIFIED_FILES: When specified/set, this first activates the --modified-files-ok option and then if any files are modified by hooks, pre-commit stages those modifications. This means that when a user invokes pre-commit as part of a git commit command, modifications made by hooks will be included in the commit and the commit command will be allowed to continue. The down side of activating this option is that if there are any un-staged changes (stashed by pre-commit) that conflict with the changes made by the hooks, then the stashed changes can be lost. I would welcome feedback or suggestions on how to prevent this.

The objective of this work is to make using pre-commit a more seamless experience. I recently suggested to my co-workers that we start using pre-commit, and I had one particularly grumpy co-worker strongly object based on the fact that if the hooks made modifications, he would be required to manually stage those modifications and execute git commit a second time. I'm hoping that many others will see value in the simplified workflow enabled by these options just like I hope my co-worker doesn't have anything else to protest about... one can dream, right?

I've added the necessary changes to the test cases to ensure these changes don't break any existing tests. I've also used these options and verified they function as expected.

@asottile
Copy link
Member

asottile commented Oct 24, 2019

nope, sorry this is intentionally not implemented -- please read the relevant issues and next time search the issue tracker and make an issue before implementing large features #1099 #1086 #879 #806 #999 #747

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

Successfully merging this pull request may close these issues.

None yet

2 participants