Skip to content

Commit b016aa8

Browse files
committed
clone: accept DEPTH env var as fallback for --depth
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>
1 parent 3e65291 commit b016aa8

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

builtin/clone.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ int cmd_clone(int argc,
10221022
usage_msg_opt(_("You must specify a repository to clone."),
10231023
builtin_clone_usage, builtin_clone_options);
10241024

1025+
if (!option_depth) {
1026+
const char *env_depth = getenv("DEPTH");
1027+
if (env_depth && *env_depth)
1028+
option_depth = xstrdup(env_depth);
1029+
}
1030+
10251031
if (option_depth || option_since || option_not.nr)
10261032
deepen = 1;
10271033
if (option_single_branch == -1)

0 commit comments

Comments
 (0)