From 4fe788b1b0ee6150173580d8fa70e7d5788cf7d3 Mon Sep 17 00:00:00 2001 From: Li Linchao Date: Thu, 1 Apr 2021 10:46:59 +0000 Subject: builtin/clone.c: add --reject-shallow option In some scenarios, users may want more history than the repository offered for cloning, which happens to be a shallow repository, can give them. But because users don't know it is a shallow repository until they download it to local, we may want to refuse to clone this kind of repository, without creating any unnecessary files. The '--depth=x' option cannot be used as a solution; the source may be deep enough to give us 'x' commits when cloned, but the user may later need to deepen the history to arbitrary depth. Teach '--reject-shallow' option to "git clone" to abort as soon as we find out that we are cloning from a shallow repository. Signed-off-by: Li Linchao Signed-off-by: Junio C Hamano --- t/t5611-clone-config.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 't/t5611-clone-config.sh') diff --git a/t/t5611-clone-config.sh b/t/t5611-clone-config.sh index 9f555b87ec..f8625f9158 100755 --- a/t/t5611-clone-config.sh +++ b/t/t5611-clone-config.sh @@ -95,6 +95,31 @@ test_expect_success 'clone -c remote..fetch= --origin=' ' test_cmp expect actual ' +test_expect_success 'set up shallow repository' ' + git clone --depth=1 --no-local . shallow-repo +' + +test_expect_success 'clone.rejectshallow=true should reject cloning shallow repo' ' + test_when_finished "rm -rf out" && + test_must_fail git -c clone.rejectshallow=true clone --no-local shallow-repo out 2>err && + test_i18ngrep -e "source repository is shallow, reject to clone." err && + + git -c clone.rejectshallow=false clone --no-local shallow-repo out +' + +test_expect_success 'option --[no-]reject-shallow override clone.rejectshallow config' ' + test_when_finished "rm -rf out" && + test_must_fail git -c clone.rejectshallow=false clone --reject-shallow --no-local shallow-repo out 2>err && + test_i18ngrep -e "source repository is shallow, reject to clone." err && + + git -c clone.rejectshallow=true clone --no-reject-shallow --no-local shallow-repo out +' + +test_expect_success 'clone.rejectshallow=true should succeed cloning normal repo' ' + test_when_finished "rm -rf out" && + git -c clone.rejectshallow=true clone --no-local . out +' + test_expect_success MINGW 'clone -c core.hideDotFiles' ' test_commit attributes .gitattributes "" && rm -rf child && -- cgit v1.2.3