From: Rong Bao Date: Fri, 16 Oct 2026 10:26:39 GMT Subject: Re: [PATCH] fetch: fix --depth= and --unshallow for multi-remote fetches Message-ID: In-Reply-To: Hi Junio, On 2026-10-16 04:03, Junio C Hamano wrote: > Rong Bao writes: > >> When running `git fetch --all --depth=` or `git fetch --all >> --unshallow` with Git 2.56.0, the fetch isn't really deepened: >> ... >> >> This is because the parent process doesn't pass the --depth= flag to the >> fetcher subprocess. >> ... >> >> Fix this by passing it when specified or implied by --unshallow. After >> fixing, both flags would work on shallow trees in conjunction with >> --all, as demonstrated below: > > The above observes that "--depth=" given to the outer "fetch --all" > is not propagated down to subfetches. That's correct and succinct. >> diff --git a/builtin/fetch.c b/builtin/fetch.c >> index b2decc6cfdb8ae86b8b1e92caa85f4961ffc47ff..a110a2dcf09c7e6764eb232bff73286753b27009 100644 >> --- a/builtin/fetch.c >> +++ b/builtin/fetch.c >> @@ -2247,6 +2247,8 @@ static void add_options_to_argv(struct strvec *argv, > > This function is used to prepare a command line to run a single > fetch in a subprocess for 'fetch --all', and also to fetch > submodules when '--recurse-submodules' is in effect. Does the > latter case share the same problem that '--depth=' is not > propagated down? Should the depth of submodules be controlled > independently by not passing '--depth=' down in the first place, > in which case, this patch may be a regression for users who depend > on the behavior? This *would* change the existing behavior when --recurse-submodules, but I beg to differ on the "regression" part. We have [0] which says: --recurse-submodules[=(yes|on-demand|no)] Control if and under what conditions new commits of submodules should be fetched too. [...] From the documented behavior, I don't see any specifics mentioning that options like --depth= should not apply to recursive submodule fetches. Besides, we're already passing other fetch options like --[no-]tags [1] to recursive submodule fetches, which dates back to 85566460897e ("fetch --all: pass --tags/--no-tags through to each remote") and also has an impact to the local submodule tree similar to --depth=. And, personally, I would read commands like "git fetch --unshallow --recurse-submodules" as "unshallow the tree, including all submodules". >> strvec_push(argv, "--tags"); >> else if (tags == TAGS_UNSET) >> strvec_push(argv, "--no-tags"); >> + if (deepen) >> + strvec_pushf(argv, "--depth=%s", depth); > > The 'deepen' variable checked here is set to true when any of > the '--depth=', '--deepen-since=