]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shallow: fix relative deepen on non-shallow repositories
authorSamo Pogačnik <samo_pogacnik@t-2.net>
Mon, 11 May 2026 19:20:42 +0000 (21:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 May 2026 00:00:16 +0000 (09:00 +0900)
The commit "3ef68ff40e (shallow: handling fetch relative-deepen,
2026-02-15)" introduced a bug where using --deepen=<n> on a non-
shallow repository incorrectly treated the value as an absolute
depth, resulting in a shallow fetch and truncated history.

This patch prevents any modification when a relative deepen is
requested on a non-shallow repository.

A test is added to ensure that history is not changed when
--deepen is used on a non-shallow repository.

Reported-by: Owen Stephens <owen@owenstephens.co.uk>
Signed-off-by: Samo Pogačnik <samo_pogacnik@t-2.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shallow.c
t/t5537-fetch-shallow.sh

index a8ad92e303d24d705e3402612cb9dc832386c304..610ff3d13bf17edcca97ce45f52ab3dee9a3eaaf 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -245,7 +245,11 @@ struct commit_list *get_shallow_commits(struct object_array *heads,
                                        int depth, int shallow_flag, int not_shallow_flag)
 {
        if (shallows && deepen_relative) {
-               depth += get_shallows_depth(heads, shallows);
+               int cur_shallow_depth = get_shallows_depth(heads, shallows);
+               if (cur_shallow_depth)
+                       depth += cur_shallow_depth;
+               else
+                       return NULL;
        }
        return get_shallows_or_depth(heads, NULL, NULL,
                                     depth, shallow_flag, not_shallow_flag);
index 6588ce62264331919110fbe729154be336ca08da..9982dd2aa6d499569340b78b61b88b35a6872f82 100755 (executable)
@@ -251,6 +251,16 @@ test_expect_success '.git/shallow is edited by repack' '
                origin "+refs/heads/*:refs/remotes/origin/*"
 '
 
+test_expect_success 'fetch --deepen does not truncate' '
+       git clone --no-local .git full-clone &&
+       git -C full-clone rev-parse --is-shallow-repository >expect &&
+       git -C full-clone log --oneline >>expect &&
+       git -C full-clone fetch --deepen=1 &&
+       git -C full-clone rev-parse --is-shallow-repository >actual &&
+       git -C full-clone log --oneline >>actual &&
+       test_cmp expect actual
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd