3 test_description
='tests for git clone -c key=value'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success
'clone -c sets config in cloned repo' '
11 git clone -c core.foo=bar . child &&
13 git --git-dir=child/.git config core.foo >actual &&
14 test_cmp expect actual
17 test_expect_success
'clone -c can set multi-keys' '
19 git clone -c core.foo=bar -c core.foo=baz . child &&
20 { echo bar; echo baz; } >expect &&
21 git --git-dir=child/.git config --get-all core.foo >actual &&
22 test_cmp expect actual
25 test_expect_success
'clone -c can set multi-keys, including some empty' '
27 git clone -c credential.helper= -c credential.helper=hi . child &&
28 printf "%s\n" "" hi >expect &&
29 git --git-dir=child/.git config --get-all credential.helper >actual &&
30 test_cmp expect actual
33 test_expect_success
'clone -c without a value is boolean true' '
35 git clone -c core.foo . child &&
37 git --git-dir=child/.git config --bool core.foo >actual &&
38 test_cmp expect actual
41 test_expect_success
'clone -c config is available during clone' '
46 git clone -c core.autocrlf . child &&
47 printf "content\\r\\n" >expect &&
48 test_cmp expect child/file
51 test_expect_success
'clone -c remote.origin.fetch=<refspec> works' '
53 git update-ref refs/grab/it refs/heads/main &&
54 git update-ref refs/leave/out refs/heads/main &&
55 git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child &&
56 git -C child for-each-ref --format="%(refname)" >actual &&
58 cat >expect <<-\EOF &&
61 refs/remotes/origin/HEAD
62 refs/remotes/origin/main
64 test_cmp expect actual
67 test_expect_success
'git -c remote.origin.fetch=<refspec> clone works' '
69 git -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" clone . child &&
70 git -C child for-each-ref --format="%(refname)" >actual &&
72 cat >expect <<-\EOF &&
75 refs/remotes/origin/HEAD
76 refs/remotes/origin/main
78 test_cmp expect actual
81 test_expect_success
'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' '
83 git clone --origin=upstream \
84 -c "remote.upstream.fetch=+refs/grab/*:refs/grab/*" \
85 -c "remote.origin.fetch=+refs/leave/*:refs/leave/*" \
87 git -C child for-each-ref --format="%(refname)" >actual &&
89 cat >expect <<-\EOF &&
92 refs/remotes/upstream/HEAD
93 refs/remotes/upstream/main
95 test_cmp expect actual
98 test_expect_success
'set up shallow repository' '
99 git clone --depth=1 --no-local . shallow-repo
102 test_expect_success
'clone.rejectshallow=true should reject cloning shallow repo' '
103 test_when_finished "rm -rf out" &&
104 test_must_fail git -c clone.rejectshallow=true clone --no-local shallow-repo out 2>err &&
105 test_i18ngrep -e "source repository is shallow, reject to clone." err &&
107 git -c clone.rejectshallow=false clone --no-local shallow-repo out
110 test_expect_success
'option --[no-]reject-shallow override clone.rejectshallow config' '
111 test_when_finished "rm -rf out" &&
112 test_must_fail git -c clone.rejectshallow=false clone --reject-shallow --no-local shallow-repo out 2>err &&
113 test_i18ngrep -e "source repository is shallow, reject to clone." err &&
115 git -c clone.rejectshallow=true clone --no-reject-shallow --no-local shallow-repo out
118 test_expect_success
'clone.rejectshallow=true should succeed cloning normal repo' '
119 test_when_finished "rm -rf out" &&
120 git -c clone.rejectshallow=true clone --no-local . out
123 test_expect_success MINGW
'clone -c core.hideDotFiles' '
124 test_commit attributes .gitattributes "" &&
126 git clone -c core.hideDotFiles=false . child &&
127 ! test_path_is_hidden child/.gitattributes &&
129 git clone -c core.hideDotFiles=dotGitOnly . child &&
130 ! test_path_is_hidden child/.gitattributes &&
132 git clone -c core.hideDotFiles=true . child &&
133 test_path_is_hidden child/.gitattributes