Skip to content

Commit d2167a8

Browse files
committed
config: test home and xdg files in list --global
The `git config list --global` output includes `$HOME/.gitconfig` (home config), but ignores `$XDG_CONFIG_HOME/git/config` (XDG config). It should include both files. Modify tests to check the following and expect a failure: - `git config list --global` should include contents from both the home and XDG config locations (assuming they are readable), not just the former. - `--show-origin` should print correct paths to both config files, assuming they exist. Also, add tests to ensure subsequent patches do not introduce regressions to `git config list`. Specifically, check that: - The home config should take precedence over the XDG config. - Without `--global`, it should not bail on unreadable/non-existent global config files. - 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. The next patch, config: read global scope via config_sequence, will implement a fix to include both config files when `--global` is specified. Reported-by: Jade Lovelace <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Delilah Ashley Wu <[email protected]> Reviewed-by: Johannes Schindelin <[email protected]>
1 parent c8df6a0 commit d2167a8

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
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 file:$HOME/.config/git/config xdg.config=true
2429+
global file:$HOME/.gitconfig home.config=true
2430+
EOF
2431+
git config ${mode_prefix}list --global --show-scope --show-origin >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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ 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 &&
73-
test_cmp expected actual
74+
! test_cmp expected actual
7475
'
7576

7677

0 commit comments

Comments
 (0)