Git development
 help / color / mirror / Atom feed
From: "Samo Pogačnik" <samo_pogacnik@t-2.net>
To: git@vger.kernel.org
Cc: l.s.r@web.de, owen@owenstephens.co.uk,
	"Samo Pogačnik" <samo_pogacnik@t-2.net>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v2] shallow: fix relative deepen on non-shallow repositories
Date: Mon, 11 May 2026 21:20:42 +0200	[thread overview]
Message-ID: <20260511192044.169557-1-samo_pogacnik@t-2.net> (raw)
In-Reply-To: <xmqqy0hqqreq.fsf@gitster.g>

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>
---
Changes since v1:
- Fixed commit reference in the commit message.

 shallow.c                |  6 +++++-
 t/t5537-fetch-shallow.sh | 10 ++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/shallow.c b/shallow.c
index a8ad92e303..610ff3d13b 100644
--- 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);
diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh
index 6588ce6226..9982dd2aa6 100755
--- a/t/t5537-fetch-shallow.sh
+++ b/t/t5537-fetch-shallow.sh
@@ -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
 
-- 
2.43.0


      reply	other threads:[~2026-05-11 19:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 11:27 [Bug] fetch --deepen truncates history in v2.54.0 Owen Stephens
2026-04-29 13:14 ` Owen Stephens
2026-04-29 13:16 ` D. Ben Knoble
2026-04-30  9:10   ` Mikael Magnusson
2026-05-02  9:22 ` René Scharfe
2026-05-02 20:26   ` René Scharfe
2026-05-05 19:27     ` Samo Pogačnik
2026-05-05 20:34       ` René Scharfe
2026-05-05 21:26         ` Samo Pogačnik
2026-05-06 21:56         ` [PATCH 1/1] shallow: fix relative deepen on non-shallow repositories Samo Pogačnik
2026-05-11  0:09           ` Junio C Hamano
2026-05-11  7:45             ` René Scharfe
2026-05-11  8:30               ` Junio C Hamano
2026-05-11 19:20                 ` Samo Pogačnik [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260511192044.169557-1-samo_pogacnik@t-2.net \
    --to=samo_pogacnik@t-2.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=owen@owenstephens.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox