Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 321210d

Browse files
committed
Run git diff with --no-ext-diff
1 parent 844c839 commit 321210d

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

pre_commit/commands/run.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def _hook_msg_start(hook, verbose):
3232

3333
def get_changed_files(new, old):
3434
return cmd_output(
35-
'git', 'diff', '--name-only', '{}...{}'.format(old, new),
35+
'git', 'diff', '--no-ext-diff', '--name-only',
36+
'{}...{}'.format(old, new),
3637
)[1].splitlines()
3738

3839

@@ -85,12 +86,16 @@ def _run_single_hook(hook, repo, args, skips, cols):
8586
))
8687
sys.stdout.flush()
8788

88-
diff_before = cmd_output('git', 'diff', retcode=None, encoding=None)
89+
diff_before = cmd_output(
90+
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
91+
)
8992
retcode, stdout, stderr = repo.run_hook(
9093
hook,
9194
tuple(filenames) if hook['pass_filenames'] else (),
9295
)
93-
diff_after = cmd_output('git', 'diff', retcode=None, encoding=None)
96+
diff_after = cmd_output(
97+
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
98+
)
9499

95100
file_modifications = diff_before != diff_after
96101

@@ -159,10 +164,10 @@ def _run_hooks(repo_hooks, args, environ):
159164
if (
160165
retval and
161166
args.show_diff_on_failure and
162-
subprocess.call(('git', 'diff', '--quiet')) != 0
167+
subprocess.call(('git', 'diff', '--quiet', '--no-ext-diff')) != 0
163168
):
164169
print('All changes made by hooks:')
165-
subprocess.call(('git', 'diff'))
170+
subprocess.call(('git', 'diff', '--no-ext-diff'))
166171
return retval
167172

168173

@@ -179,7 +184,10 @@ def _has_unmerged_paths(runner):
179184

180185
def _has_unstaged_config(runner):
181186
retcode, _, _ = runner.cmd_runner.run(
182-
('git', 'diff', '--exit-code', runner.config_file_path),
187+
(
188+
'git', 'diff', '--no-ext-diff', '--exit-code',
189+
runner.config_file_path,
190+
),
183191
retcode=None,
184192
)
185193
# be explicit, other git errors don't mean it has an unstaged config.

pre_commit/git.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ def get_conflicted_files():
6868
# this will also include the conflicted files
6969
tree_hash = cmd_output('git', 'write-tree')[1].strip()
7070
merge_diff_filenames = cmd_output(
71-
'git', 'diff', '-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only',
71+
'git', 'diff', '--no-ext-diff',
72+
'-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only',
7273
)[1].splitlines()
7374
return set(merge_conflict_filenames) | set(merge_diff_filenames)
7475

7576

7677
@memoize_by_cwd
7778
def get_staged_files():
7879
return cmd_output(
79-
'git', 'diff', '--staged', '--name-only',
80+
'git', 'diff', '--staged', '--name-only', '--no-ext-diff',
8081
# Everything except for D
8182
'--diff-filter=ACMRTUXB'
8283
)[1].splitlines()

pre_commit/staged_files_only.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def staged_files_only(cmd_runner):
2121
"""
2222
# Determine if there are unstaged files
2323
retcode, diff_stdout_binary, _ = cmd_runner.run(
24-
[
24+
(
2525
'git', 'diff', '--ignore-submodules', '--binary', '--exit-code',
2626
'--no-color', '--no-ext-diff',
27-
],
27+
),
2828
retcode=None,
2929
encoding=None,
3030
)

0 commit comments

Comments
 (0)