The fourteenth batch
[alt-git.git] / t / t1306-xdg-files.sh
blob53e5b290b9bcab0d8809e34f4343f191af4ed9dc
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_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
13 test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '
14 mkdir -p .config/git &&
15 echo "[alias]" >.config/git/config &&
16 echo " myalias = !echo in_config" >>.config/git/config &&
17 echo in_config >expected &&
18 git myalias >actual &&
19 test_cmp expected actual
23 test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
24 >.gitconfig &&
25 echo "[alias]" >.gitconfig &&
26 echo " myalias = !echo in_gitconfig" >>.gitconfig &&
27 echo in_gitconfig >expected &&
28 git myalias >actual &&
29 test_cmp expected actual
33 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
34 rm .gitconfig &&
35 echo "[user]" >.config/git/config &&
36 echo " name = read_config" >>.config/git/config &&
37 echo read_config >expected &&
38 git config --get user.name >actual &&
39 test_cmp expected actual
42 test_expect_success '"$XDG_CONFIG_HOME overrides $HOME/.config/git' '
43 mkdir -p "$HOME"/xdg/git &&
44 echo "[user]name = in_xdg" >"$HOME"/xdg/git/config &&
45 echo in_xdg >expected &&
46 XDG_CONFIG_HOME="$HOME"/xdg git config --get-all user.name >actual &&
47 test_cmp expected actual
50 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
51 >.gitconfig &&
52 echo "[user]" >.gitconfig &&
53 echo " name = read_gitconfig" >>.gitconfig &&
54 echo read_gitconfig >expected &&
55 git config --get user.name >actual &&
56 test_cmp expected actual
60 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
61 rm .gitconfig &&
62 echo user.name=read_config >expected &&
63 git config --global --list >actual &&
64 test_cmp expected actual
68 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
69 >.gitconfig &&
70 echo "[user]" >.gitconfig &&
71 echo " name = read_gitconfig" >>.gitconfig &&
72 echo user.name=read_gitconfig >expected &&
73 git config --global --list >actual &&
74 test_cmp expected actual
78 test_expect_success 'Setup' '
79 git init git &&
80 cd git &&
81 echo foo >to_be_excluded
85 test_expect_success 'Exclusion of a file in the XDG ignore file' '
86 mkdir -p "$HOME"/.config/git/ &&
87 echo to_be_excluded >"$HOME"/.config/git/ignore &&
88 test_must_fail git add to_be_excluded
91 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/ignore' '
92 mkdir -p "$HOME"/xdg/git &&
93 echo content >excluded_by_xdg_only &&
94 echo excluded_by_xdg_only >"$HOME"/xdg/git/ignore &&
95 test_when_finished "git read-tree --empty" &&
96 (XDG_CONFIG_HOME="$HOME/xdg" &&
97 export XDG_CONFIG_HOME &&
98 git add to_be_excluded &&
99 test_must_fail git add excluded_by_xdg_only
103 test_expect_success 'Exclusion in both XDG and local ignore files' '
104 echo to_be_excluded >.gitignore &&
105 test_must_fail git add to_be_excluded
109 test_expect_success 'Exclusion in a non-XDG global ignore file' '
110 rm .gitignore &&
111 echo >"$HOME"/.config/git/ignore &&
112 echo to_be_excluded >"$HOME"/my_gitignore &&
113 git config core.excludesfile "$HOME"/my_gitignore &&
114 test_must_fail git add to_be_excluded
117 test_expect_success 'Checking XDG ignore file when HOME is unset' '
118 (sane_unset HOME &&
119 git config --unset core.excludesfile &&
120 git ls-files --exclude-standard --ignored --others >actual) &&
121 test_must_be_empty 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 (sane_unset HOME &&
136 git check-attr -a f >actual) &&
137 test_must_be_empty actual
140 test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
141 mkdir -p "$HOME"/xdg/git &&
142 echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes &&
143 echo "f: attr_f: xdg" >expected &&
144 XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual &&
145 test_cmp expected actual
148 test_expect_success 'Checking attributes in both XDG and local attributes files' '
149 echo "f -attr_f" >.gitattributes &&
150 echo "f: attr_f: unset" >expected &&
151 git check-attr -a f >actual &&
152 test_cmp expected actual
156 test_expect_success 'Checking attributes in a non-XDG global attributes file' '
157 rm -f .gitattributes &&
158 echo "f attr_f=test" >"$HOME"/my_gitattributes &&
159 git config core.attributesfile "$HOME"/my_gitattributes &&
160 echo "f: attr_f: test" >expected &&
161 git check-attr -a f >actual &&
162 test_cmp expected actual
166 test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
167 mkdir -p "$HOME"/.config/git &&
168 >"$HOME"/.config/git/config &&
169 rm -f "$HOME"/.gitconfig &&
170 git config --global user.name "write_config" &&
171 echo "[user]" >expected &&
172 echo " name = write_config" >>expected &&
173 test_cmp expected "$HOME"/.config/git/config
177 test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
178 >"$HOME"/.gitconfig &&
179 git config --global user.name "write_gitconfig" &&
180 echo "[user]" >expected &&
181 echo " name = write_gitconfig" >>expected &&
182 test_cmp expected "$HOME"/.gitconfig
186 test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
187 rm -f "$HOME"/.gitconfig &&
188 rm -f "$HOME"/.config/git/config &&
189 git config --global user.name "write_gitconfig" &&
190 echo "[user]" >expected &&
191 echo " name = write_gitconfig" >>expected &&
192 test_cmp expected "$HOME"/.gitconfig
196 test_done