Merge branch 'fg/document-commit-message-stripping'
[git/mingw.git] / t / t1306-xdg-files.sh
blob8b14ab187c5e01a27bbc4964e3ac9d89e2eb8934
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 >expected &&
118 (sane_unset HOME &&
119 git config --unset core.excludesfile &&
120 git ls-files --exclude-standard --ignored >actual) &&
121 test_cmp expected actual
124 test_expect_success 'Checking attributes in the XDG attributes file' '
125 echo foo >f &&
126 git check-attr -a f >actual &&
127 test_line_count -eq 0 actual &&
128 echo "f attr_f" >"$HOME"/.config/git/attributes &&
129 echo "f: attr_f: set" >expected &&
130 git check-attr -a f >actual &&
131 test_cmp expected actual
134 test_expect_success 'Checking XDG attributes when HOME is unset' '
135 >expected &&
136 (sane_unset HOME &&
137 git check-attr -a f >actual) &&
138 test_cmp expected actual
141 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
142 mkdir -p "$HOME"/xdg/git &&
143 echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes &&
144 echo "f: attr_f: xdg" >expected &&
145 XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual &&
146 test_cmp expected actual
149 test_expect_success 'Checking attributes in both XDG and local attributes files' '
150 echo "f -attr_f" >.gitattributes &&
151 echo "f: attr_f: unset" >expected &&
152 git check-attr -a f >actual &&
153 test_cmp expected actual
157 test_expect_success 'Checking attributes in a non-XDG global attributes file' '
158 test_might_fail rm .gitattributes &&
159 echo "f attr_f=test" >"$HOME"/my_gitattributes &&
160 git config core.attributesfile "$HOME"/my_gitattributes &&
161 echo "f: attr_f: test" >expected &&
162 git check-attr -a f >actual &&
163 test_cmp expected actual
167 test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
168 mkdir -p "$HOME"/.config/git &&
169 >"$HOME"/.config/git/config &&
170 test_might_fail rm "$HOME"/.gitconfig &&
171 git config --global user.name "write_config" &&
172 echo "[user]" >expected &&
173 echo " name = write_config" >>expected &&
174 test_cmp expected "$HOME"/.config/git/config
178 test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
179 >"$HOME"/.gitconfig &&
180 git config --global user.name "write_gitconfig" &&
181 echo "[user]" >expected &&
182 echo " name = write_gitconfig" >>expected &&
183 test_cmp expected "$HOME"/.gitconfig
187 test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
188 test_might_fail rm "$HOME"/.gitconfig &&
189 test_might_fail rm "$HOME"/.config/git/config &&
190 git config --global user.name "write_gitconfig" &&
191 echo "[user]" >expected &&
192 echo " name = write_gitconfig" >>expected &&
193 test_cmp expected "$HOME"/.gitconfig
197 test_done