From 2b60353ab3ec02ba6bda0cc417d7f699b84d5131 Mon Sep 17 00:00:00 2001 From: Pierre Trespeuch Date: Fri, 28 Jun 2024 12:27:09 +0200 Subject: [PATCH] Use at least --shallow-since when git_shallow_fetch is enabled When git_shallow_fetch feature is requested, even when we need to compute a changelog, we should not fetch the full depth of the repository. Just fetch at the required depth instead. --- src/e3/anod/checkout.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/e3/anod/checkout.py b/src/e3/anod/checkout.py index 98cebe93..f94da953 100644 --- a/src/e3/anod/checkout.py +++ b/src/e3/anod/checkout.py @@ -242,16 +242,21 @@ def update_git( try: old_commit = g.rev_parse() - + shallow_cmd: str | None = None # Using fetch + checkout ensure caching is effective shallow = "git_shallow_fetch" in os.environ.get( "E3_ENABLE_FEATURE", "" - ).split(",") and (not self.compute_changelog or not old_commit) + ).split(",") + if shallow and (not self.compute_changelog or not old_commit): + shallow_cmd = "--depth=1" + else: + shallow_cmd = f"--shallow-since={old_commit}" + g.git_cmd( [ "fetch", "-f", - "--depth=1" if shallow else None, + shallow_cmd, remote_name, f"{revision}:refs/e3-checkout", ]