summaryrefslogtreecommitdiffstats
path: root/pre_commit/git.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-09-06 04:23:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-09-06 04:23:44 +0000
commit8b9f67e46f462980dd0877e752954a07bfecdb32 (patch)
tree7455f28cae7a78fdec431903475978bbff39f984 /pre_commit/git.py
parentAdding upstream version 2.14.0. (diff)
downloadpre-commit-8b9f67e46f462980dd0877e752954a07bfecdb32.tar.xz
pre-commit-8b9f67e46f462980dd0877e752954a07bfecdb32.zip
Adding upstream version 2.15.0.upstream/2.15.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/git.py')
-rw-r--r--pre_commit/git.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/pre_commit/git.py b/pre_commit/git.py
index 4bf2823..6264529 100644
--- a/pre_commit/git.py
+++ b/pre_commit/git.py
@@ -155,12 +155,15 @@ def get_all_files() -> List[str]:
def get_changed_files(old: str, new: str) -> List[str]:
- return zsplit(
- cmd_output(
- 'git', 'diff', '--name-only', '--no-ext-diff', '-z',
- f'{old}...{new}',
- )[1],
- )
+ diff_cmd = ('git', 'diff', '--name-only', '--no-ext-diff', '-z')
+ try:
+ _, out, _ = cmd_output(*diff_cmd, f'{old}...{new}')
+ except CalledProcessError: # pragma: no cover (new git)
+ # on newer git where old and new do not have a merge base git fails
+ # so we try a full diff (this is what old git did for us!)
+ _, out, _ = cmd_output(*diff_cmd, f'{old}..{new}')
+
+ return zsplit(out)
def head_rev(remote: str) -> str: