Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Documentation/git-clone.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ corresponding `--mirror` and `--no-tags` options instead.
`--no-single-branch` is given to fetch the histories near the
tips of all branches. If you want to clone submodules shallowly,
also pass `--shallow-submodules`.
When `--depth` is not given on the command line, the value of the
`GIT_CLONE_DEPTH` environment variable is used instead. This makes
nested clones spawned by wrapper tools shallow without threading
`--depth` through each invocation.

`--shallow-since=<date>`::
Create a shallow clone with a history after the specified time.
Expand Down
8 changes: 8 additions & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ int cmd_clone(int argc,
int option_reject_shallow = -1; /* unspecified */
int deepen = 0;
char *option_template = NULL, *option_depth = NULL, *option_since = NULL;
char *env_depth = NULL;
char *option_origin = NULL;
struct string_list option_not = STRING_LIST_INIT_NODUP;
const char *real_git_dir = NULL;
Expand Down Expand Up @@ -1022,6 +1023,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 *value = getenv("GIT_CLONE_DEPTH");
if (value && *value)
option_depth = env_depth = xstrdup(value);
}

Comment thread
h8d13 marked this conversation as resolved.
if (option_depth || option_since || option_not.nr)
deepen = 1;
if (option_single_branch == -1)
Expand Down Expand Up @@ -1639,6 +1646,7 @@ int cmd_clone(int argc,
string_list_clear(&server_options, 0);

free(remote_name);
free(env_depth);
strbuf_release(&reflog_msg);
strbuf_release(&branch_top);
strbuf_release(&buf);
Expand Down
16 changes: 16 additions & 0 deletions t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,22 @@ test_expect_success 'shallow clone locally' '
( cd ddsstt && git fsck )
'

test_expect_success 'GIT_CLONE_DEPTH acts as a fallback for --depth' '
GIT_CLONE_DEPTH=1 git clone --no-local src depth-env &&
test_path_is_file depth-env/.git/shallow &&
test 1 = $(git -C depth-env rev-list --count HEAD)
'

test_expect_success 'explicit --depth overrides GIT_CLONE_DEPTH' '
GIT_CLONE_DEPTH=1 git clone --depth=2 --no-local src depth-override &&
test 2 = $(git -C depth-override rev-list --count HEAD)
'

test_expect_success 'empty GIT_CLONE_DEPTH is ignored' '
GIT_CLONE_DEPTH= git clone --no-local src depth-empty &&
test_path_is_missing depth-empty/.git/shallow
'

test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
rm -rf dst.git &&
GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
Expand Down
Loading