mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
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:
parent
50848aaca2
commit
7654e1a50e
1 changed files with 5 additions and 8 deletions
|
|
@ -156,14 +156,11 @@ 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')
|
||||
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}')
|
||||
|
||||
_, out, _ = cmd_output(
|
||||
'git', 'diff-tree',
|
||||
'--name-only', '--raw', '-z',
|
||||
old, new,
|
||||
)
|
||||
return zsplit(out)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue