Skip to content

Commit ab63f93

Browse files
authored
Merge pull request #1467 from tech-chad/env_variable_pre-commit
Expose an env variable that indicates if pre-commit is running
2 parents f32bc64 + 9e0b4a9 commit ab63f93

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pre_commit/commands/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ def run(
347347
if args.checkout_type:
348348
environ['PRE_COMMIT_CHECKOUT_TYPE'] = args.checkout_type
349349

350+
# Set pre_commit flag
351+
environ['PRE_COMMIT'] = '1'
352+
350353
with contextlib.ExitStack() as exit_stack:
351354
if stash:
352355
exit_stack.enter_context(staged_files_only(store.directory))

tests/commands/run_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,12 @@ def test_skipped_without_any_setup_for_post_checkout(in_git_dir, store):
10281028
environ = {'_PRE_COMMIT_SKIP_POST_CHECKOUT': '1'}
10291029
opts = run_opts(hook_stage='post-checkout')
10301030
assert run(C.CONFIG_FILE, store, opts, environ=environ) == 0
1031+
1032+
1033+
def test_pre_commit_env_variable_set(cap_out, store, repo_with_passing_hook):
1034+
args = run_opts()
1035+
environ: EnvironT = {}
1036+
ret, printed = _do_run(
1037+
cap_out, store, repo_with_passing_hook, args, environ,
1038+
)
1039+
assert environ['PRE_COMMIT'] == '1'

0 commit comments

Comments
 (0)