@@ -47,9 +47,10 @@ test_expect_success 'help command' '
4747 echo "help 1" >in &&
4848
4949 cat >expect <<-\EOF &&
50- help 1 count 2
50+ help 1 count 3
5151 help 1 help 1
5252 help 1 get 1
53+ help 1 set 1
5354 EOF
5455
5556 git config-batch >out <in &&
@@ -63,9 +64,10 @@ test_expect_success 'help -z' '
6364 EOF
6465
6566 cat >expect <<-\EOF &&
66- 4:help 1:1 5:count 1:2
67+ 4:help 1:1 5:count 1:3
6768 4:help 1:1 4:help 1:1
6869 4:help 1:1 3:get 1:1
70+ 4:help 1:1 3:set 1:1
6971 15:unknown_command
7072 EOF
7173
@@ -205,4 +207,92 @@ test_expect_success 'get config with -z' '
205207 test_cmp expect out
206208'
207209
210+ test_expect_success ' set config by scope' '
211+ test_when_finished git config remove-section test.set &&
212+ GIT_CONFIG_SYSTEM=system-config-file &&
213+ GIT_CONFIG_NOSYSTEM=0 &&
214+ GIT_CONFIG_GLOBAL=global-config-file &&
215+ export GIT_CONFIG_SYSTEM &&
216+ export GIT_CONFIG_NOSYSTEM &&
217+ export GIT_CONFIG_GLOBAL &&
218+
219+ cat >in <<-\EOF &&
220+ set 1 system test.set.system system
221+ set 1 global test.set.global global
222+ set 1 local test.set.local local with spaces
223+ set 1 worktree test.set.worktree worktree
224+ set 1 submodule test.set.submodule submodule
225+ set 1 command test.set.command command
226+ set 1 inherited test.set.inherited inherited
227+ EOF
228+
229+ cat >expect <<-\EOF &&
230+ set 1 success system test.set.system system
231+ set 1 success global test.set.global global
232+ set 1 success local test.set.local local with spaces
233+ set 1 success worktree test.set.worktree worktree
234+ command_parse_error set
235+ command_parse_error set
236+ command_parse_error set
237+ EOF
238+
239+ git config-batch <in >out 2>err &&
240+
241+ test_must_be_empty err &&
242+ test_cmp expect out &&
243+
244+ cat >expect-values <<-EOF &&
245+ file:system-config-file system
246+ file:global-config-file global
247+ file:.git/config local with spaces
248+ file:.git/config.worktree worktree
249+ EOF
250+
251+ git config get --show-origin --regexp --all test.set.* >values &&
252+ test_cmp expect-values values
253+ '
254+
255+ test_expect_success ' set config by scope with -z' '
256+ test_when_finished git config remove-section test.set &&
257+ GIT_CONFIG_SYSTEM=system-config-file &&
258+ GIT_CONFIG_NOSYSTEM=0 &&
259+ GIT_CONFIG_GLOBAL=global-config-file &&
260+ export GIT_CONFIG_SYSTEM &&
261+ export GIT_CONFIG_NOSYSTEM &&
262+ export GIT_CONFIG_GLOBAL &&
263+
264+ cat >in <<-\EOF &&
265+ 3:set NUL 1:1 NUL 6:system NUL 15:test.set.system NUL 6:system NUL NUL
266+ 3:set NUL 1:1 NUL 6:global NUL 15:test.set.global NUL 6:global NUL NUL
267+ 3:set NUL 1:1 NUL 5:local NUL 14:test.set.local NUL 17:local with spaces NUL NUL
268+ 3:set NUL 1:1 NUL 8:worktree NUL 17:test.set.worktree NUL 8:worktree NUL NUL
269+ 3:set NUL 1:1 NUL 9:submodule NUL 18:test.set.submodule NUL 9:submodule NUL NUL
270+ 3:set NUL 1:1 NUL 7:command NUL 16:test.set.command NUL 7:command NUL NUL
271+ 3:set NUL 1:1 NUL 9:inherited NUL 18:test.set.inherited NUL 9:inherited NUL NUL
272+ EOF
273+
274+ cat >expect <<-\EOF &&
275+ 3:set 1:1 7:success 6:system 15:test.set.system 6:system
276+ 3:set 1:1 7:success 6:global 15:test.set.global 6:global
277+ 3:set 1:1 7:success 5:local 14:test.set.local 17:local with spaces
278+ 3:set 1:1 7:success 8:worktree 17:test.set.worktree 8:worktree
279+ 19:command_parse_error 3:set
280+ 19:command_parse_error 3:set
281+ 19:command_parse_error 3:set
282+ EOF
283+
284+ test_zformat git config-batch -z >out <in &&
285+ test_cmp expect out &&
286+
287+ cat >expect-values <<-EOF &&
288+ file:system-config-file system
289+ file:global-config-file global
290+ file:.git/config local with spaces
291+ file:.git/config.worktree worktree
292+ EOF
293+
294+ git config get --show-origin --regexp --all test.set.* >values &&
295+ test_cmp expect-values values
296+ '
297+
208298test_done
0 commit comments