Sync with 'maint'
[alt-git.git] / t / t5611-clone-config.sh
blob298d4befab84f2c4476c46562167a0e0a09b3981
1 #!/bin/sh
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
8 . ./test-lib.sh
10 test_expect_success 'clone -c sets config in cloned repo' '
11 rm -rf child &&
12 git clone -c core.foo=bar . child &&
13 echo bar >expect &&
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' '
19 rm -rf child &&
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' '
27 rm -rf child &&
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' '
35 rm -rf child &&
36 git clone -c core.foo . child &&
37 echo true >expect &&
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' '
43 echo content >file &&
44 git add file &&
45 git commit -m one &&
46 rm -rf child &&
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' '
53 rm -rf child &&
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 &&
60 refs/grab/it
61 refs/heads/main
62 refs/remotes/origin/HEAD
63 refs/remotes/origin/main
64 EOF
65 test_cmp expect actual
68 test_expect_success 'git -c remote.origin.fetch=<refspec> clone works' '
69 rm -rf child &&
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 &&
74 refs/grab/it
75 refs/heads/main
76 refs/remotes/origin/HEAD
77 refs/remotes/origin/main
78 EOF
79 test_cmp expect actual
82 test_expect_success 'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' '
83 rm -rf child &&
84 git clone --origin=upstream \
85 -c "remote.upstream.fetch=+refs/grab/*:refs/grab/*" \
86 -c "remote.origin.fetch=+refs/leave/*:refs/leave/*" \
87 . child &&
88 git -C child for-each-ref --format="%(refname)" >actual &&
90 cat >expect <<-\EOF &&
91 refs/grab/it
92 refs/heads/main
93 refs/remotes/upstream/HEAD
94 refs/remotes/upstream/main
95 EOF
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 "" &&
126 rm -rf child &&
127 git clone -c core.hideDotFiles=false . child &&
128 ! test_path_is_hidden child/.gitattributes &&
129 rm -rf child &&
130 git clone -c core.hideDotFiles=dotGitOnly . child &&
131 ! test_path_is_hidden child/.gitattributes &&
132 rm -rf child &&
133 git clone -c core.hideDotFiles=true . child &&
134 test_path_is_hidden child/.gitattributes
137 test_done