* Re: [PATCH] clone: accept DEPTH env var as fallback for --depth
@ 2026-06-13 17:43 Hadrien Loge
2026-06-14 1:08 ` brian m. carlson
0 siblings, 1 reply; 5+ messages in thread
From: Hadrien Loge @ 2026-06-13 17:43 UTC (permalink / raw)
To: gitster; +Cc: git, gitgitgadget, hadean-eon-dev, m
Well mainly I'm asking this for packaging (Arch/Alpine/Etc)
These all follow similar conventions (PKGBUILD/APKBUILD).
But in nested flows the ENV var seems like the proper solution.
Mainly I gave this example on github:
git clone --depth 1 url dest
cd dest
bash run.sh
here run.sh has its own clone deps (perhaps even multiple)
--depth 1 is now lost
And only ENV vars that I can think of properly propagate for CI
flows/clean chroot envirs.
Thank you for considering the solution. It would be very useful
for speeding up packaging.
Even on 5k commits history it's 900kb vs 17mb.
I have also reworked the commit to include tests/docs.
and rename to GIT_CLONE_DEPTH
Kind regards,
Hade
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] clone: accept DEPTH env var as fallback for --depth
2026-06-13 17:43 [PATCH] clone: accept DEPTH env var as fallback for --depth Hadrien Loge
@ 2026-06-14 1:08 ` brian m. carlson
0 siblings, 0 replies; 5+ messages in thread
From: brian m. carlson @ 2026-06-14 1:08 UTC (permalink / raw)
To: Hadrien Loge; +Cc: gitster, git, gitgitgadget, hadean-eon-dev, m
[-- Attachment #1: Type: text/plain, Size: 2231 bytes --]
On 2026-06-13 at 17:43:23, Hadrien Loge wrote:
> Well mainly I'm asking this for packaging (Arch/Alpine/Etc)
> These all follow similar conventions (PKGBUILD/APKBUILD).
Debian builds packages without network access because they want to make
sure that every piece of the source is in the source package, that every
package is reproducibly built, and that users can rebuild source
packages if they like without worrying about needing network access or
having their location exposed to the author.
Wouldn't that be the right decision for reproducibility and privacy
reasons? If so, then the download of the source would happen before
building and could be tailored to meet your needs with the existing
command-line option.
> But in nested flows the ENV var seems like the proper solution.
>
> Mainly I gave this example on github:
>
> git clone --depth 1 url dest
> cd dest
> bash run.sh
> here run.sh has its own clone deps (perhaps even multiple)
> --depth 1 is now lost
>
> And only ENV vars that I can think of properly propagate for CI
> flows/clean chroot envirs.
> Thank you for considering the solution. It would be very useful
> for speeding up packaging.
> Even on 5k commits history it's 900kb vs 17mb.
>
> I have also reworked the commit to include tests/docs.
> and rename to GIT_CLONE_DEPTH
So say someone has this set in their environment and then they run a
script that clones a repository and runs `git describe`. That no longer
works and the script fails because it assumed that it had history.
It's also a problem if you then do a fetch into the shallow repository
because shallow fetches are _extremely_ expensive to serve (more
expensive than full clones), so having automation that now runs
thousands of these shallow fetches means that your requests will be
throttled by the server operator whereas they wouldn't with a regular
fetch.
There's no one right solution here and while I am sympathetic to your
situation, it will also result in hard-to-reproduce breakage for other
tooling. People rely on `git clone` and similar commands only honouring
command line arguments.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] clone: accept DEPTH env var as fallback for --depth
@ 2026-06-13 1:39 h8d13 via GitGitGadget
2026-06-13 4:08 ` Matt Hunter
0 siblings, 1 reply; 5+ messages in thread
From: h8d13 via GitGitGadget @ 2026-06-13 1:39 UTC (permalink / raw)
To: git; +Cc: h8d13, h8d13
From: h8d13 <hadean-eon-dev@proton.me>
When git clone is run by a tool the user does not control directly
(CI runners, package build scripts such as makepkg, or any wrapper
that spawns nested clones), there is no way to request a shallow
clone: --depth only exists as a command-line option on the process
that invokes git clone, and unlike url.*.insteadOf there is no
configuration key that could be injected via GIT_CONFIG_* to achieve
the same effect.
Teach git clone to read a DEPTH environment variable when --depth is
not given on the command line. Since environment variables propagate
to child processes, exporting DEPTH=1 once makes every nested clone
underneath shallow, which is useful in CI pipelines and recursive
build tools. An explicit --depth on the command line still takes
precedence, and the value goes through the existing validation, so a
non-positive DEPTH dies with the same error as a non-positive
--depth.
Signed-off-by: h8d13 <hadean-eon-dev@proton.me>
---
clone: accept DEPTH env var as fallback for --depth
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2333%2Fh8d13%2Fdepth-env-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2333/h8d13/depth-env-v1
Pull-Request: https://github.com/git/git/pull/2333
builtin/clone.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/builtin/clone.c b/builtin/clone.c
index d60d1b60bc..549506f672 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1022,6 +1022,12 @@ int cmd_clone(int argc,
usage_msg_opt(_("You must specify a repository to clone."),
builtin_clone_usage, builtin_clone_options);
+ if (!option_depth) {
+ const char *env_depth = getenv("DEPTH");
+ if (env_depth && *env_depth)
+ option_depth = xstrdup(env_depth);
+ }
+
if (option_depth || option_since || option_not.nr)
deepen = 1;
if (option_single_branch == -1)
base-commit: 3e65291872de10c3f0bf05ea8c24187e7a71ebf0
--
gitgitgadget
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] clone: accept DEPTH env var as fallback for --depth
2026-06-13 1:39 h8d13 via GitGitGadget
@ 2026-06-13 4:08 ` Matt Hunter
2026-06-13 15:20 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Matt Hunter @ 2026-06-13 4:08 UTC (permalink / raw)
To: h8d13 via GitGitGadget, git; +Cc: h8d13
On Fri Jun 12, 2026 at 9:39 PM EDT, h8d13 via GitGitGadget wrote:
> @@ -1022,6 +1022,12 @@ int cmd_clone(int argc,
> usage_msg_opt(_("You must specify a repository to clone."),
> builtin_clone_usage, builtin_clone_options);
>
> + if (!option_depth) {
> + const char *env_depth = getenv("DEPTH");
Nearly all of the non-standard environment variables used by git start
with "GIT_". "GIT_CLONE_DEPTH" may be a better choice.
> + if (env_depth && *env_depth)
> + option_depth = xstrdup(env_depth);
Following normal command-line option parsing, if --depth is given, then
option_depth points to the parsed string from cmd_clone's argv array
directly and is not freed. Therefore, the string copy returned via
xstrdup also goes unfreed before it is lost.
One might argue this isn't very impactful, since we would expect the
process to exit after git-clone completes, but there are already several
explicit calls to free and related functions at the end of cmd_clone.
> + }
> +
> if (option_depth || option_since || option_not.nr)
> deepen = 1;
> if (option_single_branch == -1)
>
> base-commit: 3e65291872de10c3f0bf05ea8c24187e7a71ebf0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] clone: accept DEPTH env var as fallback for --depth
2026-06-13 4:08 ` Matt Hunter
@ 2026-06-13 15:20 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2026-06-13 15:20 UTC (permalink / raw)
To: Matt Hunter; +Cc: h8d13 via GitGitGadget, git, h8d13
"Matt Hunter" <m@lfurio.us> writes:
> On Fri Jun 12, 2026 at 9:39 PM EDT, h8d13 via GitGitGadget wrote:
>> @@ -1022,6 +1022,12 @@ int cmd_clone(int argc,
>> usage_msg_opt(_("You must specify a repository to clone."),
>> builtin_clone_usage, builtin_clone_options);
>>
>> + if (!option_depth) {
>> + const char *env_depth = getenv("DEPTH");
>
> Nearly all of the non-standard environment variables used by git start
> with "GIT_". "GIT_CLONE_DEPTH" may be a better choice.
Isn't it sufficient to add a new configuration variable in the
clone.* namespace? Unless there is a reason why it does not work, I
won't accept a patch that adds a random environment support like
this. We do not want to end up having to add other random
environment variables like GIT_CLONE_DEFAULTREMOTENAME,
CLONE_REJECTSHALLOW, CLONE_FILTERSUBMODULES for consistency.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-14 1:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-13 17:43 [PATCH] clone: accept DEPTH env var as fallback for --depth Hadrien Loge
2026-06-14 1:08 ` brian m. carlson
-- strict thread matches above, loose matches on Subject: below --
2026-06-13 1:39 h8d13 via GitGitGadget
2026-06-13 4:08 ` Matt Hunter
2026-06-13 15:20 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox