Git development
 help / color / mirror / Atom feed
From: "h8d13 via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: h8d13 <hadean-eon-dev@proton.me>, h8d13 <hadean-eon-dev@proton.me>
Subject: [PATCH] clone: accept DEPTH env var as fallback for --depth
Date: Sat, 13 Jun 2026 01:39:40 +0000	[thread overview]
Message-ID: <pull.2333.git.git.1781314780645.gitgitgadget@gmail.com> (raw)

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

             reply	other threads:[~2026-06-13  1:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-13  1:39 h8d13 via GitGitGadget [this message]
2026-06-13  4:08 ` [PATCH] clone: accept DEPTH env var as fallback for --depth Matt Hunter

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=pull.2333.git.git.1781314780645.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hadean-eon-dev@proton.me \
    /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