Git 2.45
[git/gitster.git] / t / t1306-xdg-files.sh
blob40d3c42618c04f8b0e656af83fb2e303601dd7ff
1 #!/bin/sh
3 # Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4 # Thomas Nguy, Khoi Nguyen
5 # Grenoble INP Ensimag
8 test_description='Compatibility with $XDG_CONFIG_HOME/git/ files'
10 . ./test-lib.sh
12 test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '
13 mkdir -p .config/git &&
14 echo "[alias]" >.config/git/config &&
15 echo " myalias = !echo in_config" >>.config/git/config &&
16 echo in_config >expected &&
17 git myalias >actual &&
18 test_cmp expected actual
22 test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
23 >.gitconfig &&
24 echo "[alias]" >.gitconfig &&
25 echo " myalias = !echo in_gitconfig" >>.gitconfig &&
26 echo in_gitconfig >expected &&
27 git myalias >actual &&
28 test_cmp expected actual
32 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
33 rm .gitconfig &&
34 echo "[user]" >.config/git/config &&
35 echo " name = read_config" >>.config/git/config &&
36 echo read_config >expected &&
37 git config --get user.name >actual &&
38 test_cmp expected actual
41 test_expect_success '"$XDG_CONFIG_HOME overrides $HOME/.config/git' '
42 mkdir -p "$HOME"/xdg/git &&
43 echo "[user]name = in_xdg" >"$HOME"/xdg/git/config &&
44 echo in_xdg >expected &&
45 XDG_CONFIG_HOME="$HOME"/xdg git config --get-all user.name >actual &&
46 test_cmp expected actual
49 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
50 >.gitconfig &&
51 echo "[user]" >.gitconfig &&
52 echo " name = read_gitconfig" >>.gitconfig &&
53 echo read_gitconfig >expected &&
54 git config --get user.name >actual &&
55 test_cmp expected actual
59 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
60 rm .gitconfig &&
61 echo user.name=read_config >expected &&
62 git config --global --list >actual &&
63 test_cmp expected actual
67 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
68 >.gitconfig &&
69 echo "[user]" >.gitconfig &&
70 echo " name = read_gitconfig" >>.gitconfig &&
71 echo user.name=read_gitconfig >expected &&
72 git config --global --list >actual &&
73 test_cmp expected actual
77 test_expect_success 'Setup' '
78 git init git &&
79 cd git &&
80 echo foo >to_be_excluded
84 test_expect_success 'Exclusion of a file in the XDG ignore file' '
85 mkdir -p "$HOME"/.config/git/ &&
86 echo to_be_excluded >"$HOME"/.config/git/ignore &&
87 test_must_fail git add to_be_excluded
90 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/ignore' '
91 mkdir -p "$HOME"/xdg/git &&
92 echo content >excluded_by_xdg_only &&
93 echo excluded_by_xdg_only >"$HOME"/xdg/git/ignore &&
94 test_when_finished "git read-tree --empty" &&
95 (XDG_CONFIG_HOME="$HOME/xdg" &&
96 export XDG_CONFIG_HOME &&
97 git add to_be_excluded &&
98 test_must_fail git add excluded_by_xdg_only
102 test_expect_success 'Exclusion in both XDG and local ignore files' '
103 echo to_be_excluded >.gitignore &&
104 test_must_fail git add to_be_excluded
108 test_expect_success 'Exclusion in a non-XDG global ignore file' '
109 rm .gitignore &&
110 echo >"$HOME"/.config/git/ignore &&
111 echo to_be_excluded >"$HOME"/my_gitignore &&
112 git config core.excludesfile "$HOME"/my_gitignore &&
113 test_must_fail git add to_be_excluded
116 test_expect_success 'Checking XDG ignore file when HOME is unset' '
117 (sane_unset HOME &&
118 git config --unset core.excludesfile &&
119 git ls-files --exclude-standard --ignored --others >actual) &&
120 test_must_be_empty actual
123 test_expect_success 'Checking attributes in the XDG attributes file' '
124 echo foo >f &&
125 git check-attr -a f >actual &&
126 test_line_count -eq 0 actual &&
127 echo "f attr_f" >"$HOME"/.config/git/attributes &&
128 echo "f: attr_f: set" >expected &&
129 git check-attr -a f >actual &&
130 test_cmp expected actual
133 test_expect_success 'Checking XDG attributes when HOME is unset' '
134 (sane_unset HOME &&
135 git check-attr -a f >actual) &&
136 test_must_be_empty actual
139 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
140 mkdir -p "$HOME"/xdg/git &&
141 echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes &&
142 echo "f: attr_f: xdg" >expected &&
143 XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual &&
144 test_cmp expected actual
147 test_expect_success 'Checking attributes in both XDG and local attributes files' '
148 echo "f -attr_f" >.gitattributes &&
149 echo "f: attr_f: unset" >expected &&
150 git check-attr -a f >actual &&
151 test_cmp expected actual
155 test_expect_success 'Checking attributes in a non-XDG global attributes file' '
156 rm -f .gitattributes &&
157 echo "f attr_f=test" >"$HOME"/my_gitattributes &&
158 git config core.attributesfile "$HOME"/my_gitattributes &&
159 echo "f: attr_f: test" >expected &&
160 git check-attr -a f >actual &&
161 test_cmp expected actual
165 test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
166 mkdir -p "$HOME"/.config/git &&
167 >"$HOME"/.config/git/config &&
168 rm -f "$HOME"/.gitconfig &&
169 git config --global user.name "write_config" &&
170 echo "[user]" >expected &&
171 echo " name = write_config" >>expected &&
172 test_cmp expected "$HOME"/.config/git/config
176 test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
177 >"$HOME"/.gitconfig &&
178 git config --global user.name "write_gitconfig" &&
179 echo "[user]" >expected &&
180 echo " name = write_gitconfig" >>expected &&
181 test_cmp expected "$HOME"/.gitconfig
185 test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
186 rm -f "$HOME"/.gitconfig &&
187 rm -f "$HOME"/.config/git/config &&
188 git config --global user.name "write_gitconfig" &&
189 echo "[user]" >expected &&
190 echo " name = write_gitconfig" >>expected &&
191 test_cmp expected "$HOME"/.gitconfig
195 test_done