]>
Commit | Line | Data |
---|---|---|
84054f79 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='tests for git clone -c key=value' | |
95cf2c01 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
dd4143e7 | 7 | TEST_PASSES_SANITIZE_LEAK=true |
84054f79 JK |
8 | . ./test-lib.sh |
9 | ||
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 | |
16 | ' | |
17 | ||
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 && | |
08495412 | 21 | test_write_lines bar baz >expect && |
84054f79 JK |
22 | git --git-dir=child/.git config --get-all core.foo >actual && |
23 | test_cmp expect actual | |
24 | ' | |
25 | ||
db4eca1f JN |
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 | |
32 | ' | |
33 | ||
84054f79 JK |
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 | |
40 | ' | |
41 | ||
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 | |
50 | ' | |
51 | ||
515be833 SG |
52 | test_expect_success 'clone -c remote.origin.fetch=<refspec> works' ' |
53 | rm -rf child && | |
95cf2c01 JS |
54 | git update-ref refs/grab/it refs/heads/main && |
55 | git update-ref refs/leave/out refs/heads/main && | |
515be833 SG |
56 | git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child && |
57 | git -C child for-each-ref --format="%(refname)" >actual && | |
58 | ||
59 | cat >expect <<-\EOF && | |
60 | refs/grab/it | |
95cf2c01 | 61 | refs/heads/main |
515be833 | 62 | refs/remotes/origin/HEAD |
95cf2c01 | 63 | refs/remotes/origin/main |
515be833 SG |
64 | EOF |
65 | test_cmp expect actual | |
66 | ' | |
67 | ||
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 && | |
72 | ||
73 | cat >expect <<-\EOF && | |
74 | refs/grab/it | |
95cf2c01 | 75 | refs/heads/main |
515be833 | 76 | refs/remotes/origin/HEAD |
95cf2c01 | 77 | refs/remotes/origin/main |
515be833 SG |
78 | EOF |
79 | test_cmp expect actual | |
80 | ' | |
81 | ||
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 && | |
89 | ||
90 | cat >expect <<-\EOF && | |
91 | refs/grab/it | |
95cf2c01 | 92 | refs/heads/main |
515be833 | 93 | refs/remotes/upstream/HEAD |
95cf2c01 | 94 | refs/remotes/upstream/main |
515be833 SG |
95 | EOF |
96 | test_cmp expect actual | |
97 | ' | |
98 | ||
4fe788b1 LL |
99 | test_expect_success 'set up shallow repository' ' |
100 | git clone --depth=1 --no-local . shallow-repo | |
101 | ' | |
102 | ||
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 && | |
6789275d | 106 | test_grep -e "source repository is shallow, reject to clone." err && |
4fe788b1 LL |
107 | |
108 | git -c clone.rejectshallow=false clone --no-local shallow-repo out | |
109 | ' | |
110 | ||
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 && | |
6789275d | 114 | test_grep -e "source repository is shallow, reject to clone." err && |
4fe788b1 LL |
115 | |
116 | git -c clone.rejectshallow=true clone --no-reject-shallow --no-local shallow-repo out | |
117 | ' | |
118 | ||
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 | |
122 | ' | |
123 | ||
f30afdab JS |
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 && | |
176a66a7 | 128 | ! test_path_is_hidden child/.gitattributes && |
f30afdab JS |
129 | rm -rf child && |
130 | git clone -c core.hideDotFiles=dotGitOnly . child && | |
176a66a7 | 131 | ! test_path_is_hidden child/.gitattributes && |
f30afdab JS |
132 | rm -rf child && |
133 | git clone -c core.hideDotFiles=true . child && | |
176a66a7 | 134 | test_path_is_hidden child/.gitattributes |
f30afdab JS |
135 | ' |
136 | ||
84054f79 | 137 | test_done |