From: Samo Pogačnik Date: Tue, 05 May 2026 19:27:52 GMT Subject: Re: [Bug] fetch --deepen truncates history in v2.54.0 Message-ID: <2afd4a28a9a542f8baeab488cb0801d6b98adb0a.camel@t-2.net> In-Reply-To: On Sat, 2026-05-02 at 22:26 +0200, René Scharfe wrote: > On 5/2/26 11:22 AM, René Scharfe wrote: > > On 4/29/26 1:27 PM, Owen Stephens wrote: > > > > What did you do before the bug happened? (Steps to reproduce your issue) > > > > > > Repeatedy called `git fetch --deepen 2` inside a shallow repo that was a > > > file:// clone of another repo. Once all commits had been fetched, a > > > subsequent > > > `fetch --deepen` appears to "reset" the repo back to being shallow with a > > > depth > > > of 2. A reproduction script is included below. This issue appears to have > > > been > > > introduced in v2.54.0. > > > > > > > What did you expect to happen? (Expected behavior) > > > > > > I expected `git fetch --deepen` in a non-shallow repo with no upstream > > > commits > > > to be a no-op. > > > > > > > What happened instead? (Actual behavior) > > > > > > `git log` history is truncated to two commits, and repo is considered > > > shallow > > > by `git rev-parse --is-shallow-repository`. > > > > > > > What's different between what you expected and what actually happened? > > > > > > The previously-present commits in `git log` are missing, and the repo is > > > again > > > considered shallow. > > > > > > > Anything else you want to add: > > > > > > Commit 3ef68ff seems relevant. > > > > Indeed, bisect identifies 3ef68ff40e (shallow: handling fetch relative- > > deepen, > > 2026-02-15) and reverting it fixes the issue.  Copying its author. > > Here's a simple fix, but it feels like cheating.  A proper one should > live in shallow.c, no? > > > diff --git a/builtin/fetch.c b/builtin/fetch.c > index a22c319467..310099b96d 100644 > --- a/builtin/fetch.c > +++ b/builtin/fetch.c > @@ -2664,7 +2664,8 @@ int cmd_fetch(int argc, >   die(_("negative depth in --deepen is not > supported")); >   if (depth) >   die(_("options '%s' and '%s' cannot be used > together"), "--deepen", "--depth"); > - depth = xstrfmt("%d", deepen_relative); > + if (is_repository_shallow(the_repository)) > + depth = xstrfmt("%d", deepen_relative); >   } >   if (unshallow) { >   if (depth) > Hi, thanks for pointing out this edge case. Would you care to check the following change (the provided test is also a bit modified): diff --git a/shallow.c b/shallow.c index a156006d88..ec95653132 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