Add PRE_COMMIT_ALL_FILES environment variable

Add a `PRE_COMMIT_ALL_FILES` environment variable to allow hooks to
determine if pre-commit was called with `--all-files`. This can be
useful if different behavior is desired when running pre-commit over all
files vs only staged files.
This commit is contained in:
Jameel Al-Aziz 2022-02-17 18:52:18 -08:00
parent 7858ad066f
commit e03b5eb218
No known key found for this signature in database
GPG key ID: D2C1CC4F32861B8D
2 changed files with 12 additions and 0 deletions

View file

@ -388,6 +388,9 @@ def run(
if args.rewrite_command:
environ['PRE_COMMIT_REWRITE_COMMAND'] = args.rewrite_command
if args.all_files:
environ['PRE_COMMIT_ALL_FILES'] = '1' if args.all_files else ''
# Set pre_commit flag
environ['PRE_COMMIT'] = '1'

View file

@ -524,6 +524,15 @@ def test_checkout_type(cap_out, store, repo_with_passing_hook):
assert environ['PRE_COMMIT_CHECKOUT_TYPE'] == '1'
def test_all_files(cap_out, store, repo_with_passing_hook):
args = run_opts(all_files=True)
environ: MutableMapping[str, str] = {}
ret, printed = _do_run(
cap_out, store, repo_with_passing_hook, args, environ,
)
assert environ['PRE_COMMIT_ALL_FILES'] == '1'
def test_has_unmerged_paths(in_merge_conflict):
assert _has_unmerged_paths() is True
cmd_output('git', 'add', '.')