mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-18 11:31:46 +04:00
New option to auto-add files modified by hooks
This commit is contained in:
parent
858e89865e
commit
094f8aa0a4
4 changed files with 21 additions and 1 deletions
|
|
@ -129,7 +129,7 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
|||
diff_after = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
|
||||
|
||||
file_modifications = diff_before != diff_after
|
||||
modified_ok = args.modified_files_ok
|
||||
modified_ok = args.modified_files_ok or args.add_modified
|
||||
|
||||
# If the hook makes changes, fail the commit
|
||||
if not modified_ok and file_modifications:
|
||||
|
|
@ -169,6 +169,10 @@ def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
|||
output.write_line(out.strip(), logfile_name=hook.log_file)
|
||||
output.write_line()
|
||||
|
||||
if file_modifications and modified_ok:
|
||||
output.write_line('Adding modified files to index\n')
|
||||
git.add_all()
|
||||
|
||||
return retcode
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue