fix(git): Use diff-tree instead of diff

which does not require all intermediate commits to exists, which helps
when running from CI/CD pipelines which do shallow clones for
performance reasons.

Inspired by
<https://forum.gitlab.com/t/ci-cd-pipeline-get-list-of-changed-files/26847/25>
This commit is contained in:
Philipp Hahn 2023-01-20 11:48:42 +01:00
parent 50848aaca2
commit 7654e1a50e

View file

@ -156,14 +156,11 @@ def get_all_files() -> list[str]:
def get_changed_files(old: str, new: str) -> list[str]: def get_changed_files(old: str, new: str) -> list[str]:
diff_cmd = ('git', 'diff', '--name-only', '--no-ext-diff', '-z') _, out, _ = cmd_output(
try: 'git', 'diff-tree',
_, out, _ = cmd_output(*diff_cmd, f'{old}...{new}') '--name-only', '--raw', '-z',
except CalledProcessError: # pragma: no cover (new git) old, new,
# 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) return zsplit(out)