Skip to content

Commit eea0169

Browse files
delilahwgitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfd1063 commit eea0169

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
@@ -2362,6 +2362,71 @@ test_expect_success '--show-scope with --default' '
23622362
test_cmp expect actual
23632363
'
23642364

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