Skip to content

Commit

Permalink
Add --ignore-submodules to most git diff calls
Browse files Browse the repository at this point in the history
  • Loading branch information
m-rsha committed Nov 2, 2022
1 parent 4689fe5 commit bf32cbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pre_commit/commands/run.py
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 13 additions & 5 deletions pre_commit/git.py
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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


Expand Down

0 comments on commit bf32cbe

Please sign in to comment.