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
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'clone -c sets config in cloned repo' '
12 git clone -c core.foo=bar . child &&
14 git --git-dir=child/.git config core.foo >actual &&
15 test_cmp expect actual
18 test_expect_success
'clone -c can set multi-keys' '
20 git clone -c core.foo=bar -c core.foo=baz . child &&
21 test_write_lines bar baz >expect &&
22 git --git-dir=child/.git config --get-all core.foo >actual &&
23 test_cmp expect actual
26 test_expect_success
'clone -c can set multi-keys, including some empty' '
28 git clone -c credential.helper= -c credential.helper=hi . child &&
29 printf "%s\n" "" hi >expect &&
30 git --git-dir=child/.git config --get-all credential.helper >actual &&
31 test_cmp expect actual
34 test_expect_success
'clone -c without a value is boolean true' '
36 git clone -c core.foo . child &&
38 git --git-dir=child/.git config --bool core.foo >actual &&
39 test_cmp expect actual
42 test_expect_success
'clone -c config is available during clone' '
47 git clone -c core.autocrlf . child &&
48 printf "content\\r\\n" >expect &&
49 test_cmp expect child/file
52 test_expect_success
'clone -c remote.origin.fetch=<refspec> works' '
54 git update-ref refs/grab/it refs/heads/main &&
55 git update-ref refs/leave/out refs/heads/main &&
56 git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child &&
57 git -C child for-each-ref --format="%(refname)" >actual &&
59 cat >expect <<-\EOF &&
62 refs/remotes/origin/HEAD
63 refs/remotes/origin/main
65 test_cmp expect actual
68 test_expect_success
'git -c remote.origin.fetch=<refspec> clone works' '
70 git -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" clone . child &&
71 git -C child for-each-ref --format="%(refname)" >actual &&
73 cat >expect <<-\EOF &&
76 refs/remotes/origin/HEAD
77 refs/remotes/origin/main
79 test_cmp expect actual
82 test_expect_success
'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' '
84 git clone --origin=upstream \
85 -c "remote.upstream.fetch=+refs/grab/*:refs/grab/*" \
86 -c "remote.origin.fetch=+refs/leave/*:refs/leave/*" \
88 git -C child for-each-ref --format="%(refname)" >actual &&
90 cat >expect <<-\EOF &&
93 refs/remotes/upstream/HEAD
94 refs/remotes/upstream/main
96 test_cmp expect actual
99 test_expect_success
'set up shallow repository' '
100 git clone --depth=1 --no-local . shallow-repo
103 test_expect_success
'clone.rejectshallow=true should reject cloning shallow repo' '
104 test_when_finished "rm -rf out" &&
105 test_must_fail git -c clone.rejectshallow=true clone --no-local shallow-repo out 2>err &&
106 test_grep -e "source repository is shallow, reject to clone." err &&
108 git -c clone.rejectshallow=false clone --no-local shallow-repo out
111 test_expect_success
'option --[no-]reject-shallow override clone.rejectshallow config' '
112 test_when_finished "rm -rf out" &&
113 test_must_fail git -c clone.rejectshallow=false clone --reject-shallow --no-local shallow-repo out 2>err &&
114 test_grep -e "source repository is shallow, reject to clone." err &&
116 git -c clone.rejectshallow=true clone --no-reject-shallow --no-local shallow-repo out
119 test_expect_success
'clone.rejectshallow=true should succeed cloning normal repo' '
120 test_when_finished "rm -rf out" &&
121 git -c clone.rejectshallow=true clone --no-local . out
124 test_expect_success MINGW
'clone -c core.hideDotFiles' '
125 test_commit attributes .gitattributes "" &&
127 git clone -c core.hideDotFiles=false . child &&
128 ! test_path_is_hidden child/.gitattributes &&
130 git clone -c core.hideDotFiles=dotGitOnly . child &&
131 ! test_path_is_hidden child/.gitattributes &&
133 git clone -c core.hideDotFiles=true . child &&
134 test_path_is_hidden child/.gitattributes