Skip to content

Commit f28d131

Browse files
committed
config: test home and xdg files in list --global
The `git config list --global` output includes `$HOME/.gitconfig`, but ignores `$XDG_CONFIG_HOME/git/config`. It should include both files. Modify tests to check for this expected behavior: A. `git config list --global` should include contents from both the home and XDG config locations (assuming they are readable), not just the former. Also, add tests to ensure that the subsequence patches do not introduce regressions on the behavior of `git config list`: B. The home config should take precedence over the XDG config. C. Without `--global`, it should not bail on unreadable/non-existent global config files. D. With `--global`, it should bail when both `$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config` are unreadable. It should not bail if at least one of them is readable. Signed-off-by: Delilah Ashley Wu <[email protected]>
1 parent cf6f63e commit f28d131

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

t/t1300-config.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,71 @@ test_expect_success '--show-scope with --default' '
23672367
test_cmp expect actual
23682368
'
23692369

2370+
test_expect_success 'list with nonexistent global config' '
2371+
rm -rf "$HOME"/.gitconfig "$HOME"/.config/git/config &&
2372+
git config ${mode_prefix}list --show-scope
2373+
'
2374+
2375+
test_expect_success 'list --global with nonexistent global config' '
2376+
rm -rf "$HOME"/.gitconfig "$HOME"/.config/git/config &&
2377+
test_must_fail git config ${mode_prefix}list --global --show-scope
2378+
'
2379+
2380+
test_expect_success 'list --global with only home' '
2381+
rm -rf "$HOME"/.config/git/config &&
2382+
2383+
test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2384+
cat >"$HOME"/.gitconfig <<-EOF &&
2385+
[home]
2386+
config = true
2387+
EOF
2388+
2389+
cat >expect <<-EOF &&
2390+
global home.config=true
2391+
EOF
2392+
git config ${mode_prefix}list --global --show-scope >output &&
2393+
test_cmp expect output
2394+
'
2395+
2396+
test_expect_success 'list --global with only xdg' '
2397+
rm -f "$HOME"/.gitconfig &&
2398+
2399+
test_when_finished rm -rf \"\$HOME\"/.config/git &&
2400+
mkdir -p "$HOME"/.config/git &&
2401+
cat >"$HOME"/.config/git/config <<-EOF &&
2402+
[xdg]
2403+
config = true
2404+
EOF
2405+
2406+
cat >expect <<-EOF &&
2407+
global xdg.config=true
2408+
EOF
2409+
git config ${mode_prefix}list --global --show-scope >output &&
2410+
test_cmp expect output
2411+
'
2412+
2413+
test_expect_success 'list --global with both home and xdg' '
2414+
test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2415+
cat >"$HOME"/.gitconfig <<-EOF &&
2416+
[home]
2417+
config = true
2418+
EOF
2419+
2420+
test_when_finished rm -rf \"\$HOME\"/.config/git &&
2421+
mkdir -p "$HOME"/.config/git &&
2422+
cat >"$HOME"/.config/git/config <<-EOF &&
2423+
[xdg]
2424+
config = true
2425+
EOF
2426+
2427+
cat >expect <<-EOF &&
2428+
global xdg.config=true
2429+
global home.config=true
2430+
EOF
2431+
git config ${mode_prefix}list --global --show-scope >output &&
2432+
test_cmp expect output
2433+
'
2434+
23702435
test_expect_success 'override global and system config' '
23712436
test_when_finished rm -f \"\$HOME\"/.gitconfig &&
23722437
cat >"$HOME"/.gitconfig <<-EOF &&

t/t1306-xdg-files.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists'
6868
>.gitconfig &&
6969
echo "[user]" >.gitconfig &&
7070
echo " name = read_gitconfig" >>.gitconfig &&
71-
echo user.name=read_gitconfig >expected &&
71+
echo user.name=read_config >expected &&
72+
echo user.name=read_gitconfig >>expected &&
7273
git config --global --list >actual &&
7374
test_cmp expected actual
7475
'

0 commit comments

Comments
 (0)