MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / run

Function run

pre_commit/commands/run.py:338–448  ·  view source on GitHub ↗
(
        config_file: str,
        store: Store,
        args: argparse.Namespace,
        environ: MutableMapping[str, str] = os.environ,
)

Source from the content-addressed store, hash-verified

336
337
338def run(
339 config_file: str,
340 store: Store,
341 args: argparse.Namespace,
342 environ: MutableMapping[str, str] = os.environ,
343) -> int:
344 stash = not args.all_files and not args.files
345
346 # Check if we have unresolved merge conflict files and fail fast.
347 if stash and _has_unmerged_paths():
348 logger.error('Unmerged files. Resolve before committing.')
349 return 1
350 if bool(args.from_ref) != bool(args.to_ref):
351 logger.error('Specify both --from-ref and --to-ref.')
352 return 1
353 if stash and _has_unstaged_config(config_file):
354 logger.error(
355 f'Your pre-commit configuration is unstaged.\n'
356 f'`git add {config_file}` to fix this.',
357 )
358 return 1
359 if (
360 args.hook_stage in {'prepare-commit-msg', 'commit-msg'} and
361 not args.commit_msg_filename
362 ):
363 logger.error(
364 f'`--commit-msg-filename` is required for '
365 f'`--hook-stage {args.hook_stage}`',
366 )
367 return 1
368 # prevent recursive post-checkout hooks (#1418)
369 if (
370 args.hook_stage == 'post-checkout' and
371 environ.get('_PRE_COMMIT_SKIP_POST_CHECKOUT')
372 ):
373 return 0
374
375 # Expose prepare_commit_message_source / commit_object_name
376 # as environment variables for the hooks
377 if args.prepare_commit_message_source:
378 environ['PRE_COMMIT_COMMIT_MSG_SOURCE'] = (
379 args.prepare_commit_message_source
380 )
381
382 if args.commit_object_name:
383 environ['PRE_COMMIT_COMMIT_OBJECT_NAME'] = args.commit_object_name
384
385 # Expose from-ref / to-ref as environment variables for hooks to consume
386 if args.from_ref and args.to_ref:
387 # legacy names
388 environ['PRE_COMMIT_ORIGIN'] = args.from_ref
389 environ['PRE_COMMIT_SOURCE'] = args.to_ref
390 # new names
391 environ['PRE_COMMIT_FROM_REF'] = args.from_ref
392 environ['PRE_COMMIT_TO_REF'] = args.to_ref
393
394 if args.pre_rebase_upstream and args.pre_rebase_branch:
395 environ['PRE_COMMIT_PRE_REBASE_UPSTREAM'] = args.pre_rebase_upstream

Callers 5

mainFunction · 0.90
hook_implFunction · 0.90
try_repoFunction · 0.90
_do_runFunction · 0.90

Calls 8

staged_files_onlyFunction · 0.90
all_hooksFunction · 0.90
install_hook_envsFunction · 0.90
_has_unmerged_pathsFunction · 0.85
_has_unstaged_configFunction · 0.85
_get_skipsFunction · 0.85
_run_hooksFunction · 0.85
getMethod · 0.45

Tested by 2

_do_runFunction · 0.72