diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 429e04c60..0831e6ed2 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -304,7 +304,7 @@ def _run_hooks( git_color_opt = 'always' if args.color else 'never' subprocess.call(( 'git', '--no-pager', 'diff', '--no-ext-diff', - f'--color={git_color_opt}', + '--ignore-submodules', f'--color={git_color_opt}', )) return retval @@ -317,8 +317,8 @@ def _has_unmerged_paths() -> bool: def _has_unstaged_config(config_file: str) -> bool: retcode, _, _ = cmd_output_b( - 'git', 'diff', '--no-ext-diff', '--exit-code', config_file, - check=False, + 'git', 'diff', '--no-ext-diff', '--ignore-submodules', + '--exit-code', config_file, check=False, ) # be explicit, other git errors don't mean it has an unstaged config. return retcode == 1 diff --git a/pre_commit/git.py b/pre_commit/git.py index 99538b1b9..5eed0f5a4 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -130,8 +130,9 @@ def get_conflicted_files() -> set[str]: tree_hash = cmd_output('git', 'write-tree')[1].strip() merge_diff_filenames = zsplit( cmd_output( - 'git', 'diff', '--name-only', '--no-ext-diff', '-z', - '-m', tree_hash, 'HEAD', 'MERGE_HEAD', + 'git', 'diff', '--name-only', '--no-ext-diff', + '--ignore-submodules', '-z', '-m', + tree_hash, 'HEAD', 'MERGE_HEAD', )[1], ) return set(merge_conflict_filenames) | set(merge_diff_filenames) @@ -150,7 +151,8 @@ def get_staged_files(cwd: str | None = None) -> list[str]: def intent_to_add_files() -> list[str]: _, stdout, _ = cmd_output( - 'git', 'diff', '--diff-filter=A', '--name-only', '-z', + 'git', 'diff', '--no-ext-diff', '--ignore-submodules', + '--diff-filter=A', '--name-only', '-z', ) return zsplit(stdout) @@ -160,7 +162,10 @@ def get_all_files() -> list[str]: def get_changed_files(old: str, new: str) -> list[str]: - diff_cmd = ('git', 'diff', '--name-only', '--no-ext-diff', '-z') + diff_cmd = ( + 'git', 'diff', '--name-only', '--no-ext-diff', + '--ignore-submodules', '-z', + ) try: _, out, _ = cmd_output(*diff_cmd, f'{old}...{new}') except CalledProcessError: # pragma: no cover (new git) @@ -177,7 +182,10 @@ def head_rev(remote: str) -> str: def has_diff(*args: str, repo: str = '.') -> bool: - cmd = ('git', 'diff', '--quiet', '--no-ext-diff', *args) + cmd = ( + 'git', 'diff', '--quiet', '--no-ext-diff', + '--ignore-submodules', *args, + ) return cmd_output_b(*cmd, cwd=repo, check=False)[0] == 1