attr: make sure we have an xdg path before using it
[git.git] / t / t1306-xdg-files.sh
blob1569596ab3beee2cecb14349f7676faa4c6ee02e
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
42 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
43 >.gitconfig &&
44 echo "[user]" >.gitconfig &&
45 echo " name = read_gitconfig" >>.gitconfig &&
46 echo read_gitconfig >expected &&
47 git config --get user.name >actual &&
48 test_cmp expected actual
52 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
53 rm .gitconfig &&
54 echo user.name=read_config >expected &&
55 git config --global --list >actual &&
56 test_cmp expected actual
60 test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
61 >.gitconfig &&
62 echo "[user]" >.gitconfig &&
63 echo " name = read_gitconfig" >>.gitconfig &&
64 echo user.name=read_gitconfig >expected &&
65 git config --global --list >actual &&
66 test_cmp expected actual
70 test_expect_success 'Setup' '
71 git init git &&
72 cd git &&
73 echo foo >to_be_excluded
77 test_expect_success 'Exclusion of a file in the XDG ignore file' '
78 mkdir -p "$HOME"/.config/git/ &&
79 echo to_be_excluded >"$HOME"/.config/git/ignore &&
80 test_must_fail git add to_be_excluded
84 test_expect_success 'Exclusion in both XDG and local ignore files' '
85 echo to_be_excluded >.gitignore &&
86 test_must_fail git add to_be_excluded
90 test_expect_success 'Exclusion in a non-XDG global ignore file' '
91 rm .gitignore &&
92 echo >"$HOME"/.config/git/ignore &&
93 echo to_be_excluded >"$HOME"/my_gitignore &&
94 git config core.excludesfile "$HOME"/my_gitignore &&
95 test_must_fail git add to_be_excluded
99 test_expect_success 'Checking attributes in the XDG attributes file' '
100 echo foo >f &&
101 git check-attr -a f >actual &&
102 test_line_count -eq 0 actual &&
103 echo "f attr_f" >"$HOME"/.config/git/attributes &&
104 echo "f: attr_f: set" >expected &&
105 git check-attr -a f >actual &&
106 test_cmp expected actual
109 test_expect_success 'Checking XDG attributes when HOME is unset' '
110 >expected &&
111 (sane_unset HOME &&
112 git check-attr -a f >actual) &&
113 test_cmp expected actual
116 test_expect_success 'Checking attributes in both XDG and local attributes files' '
117 echo "f -attr_f" >.gitattributes &&
118 echo "f: attr_f: unset" >expected &&
119 git check-attr -a f >actual &&
120 test_cmp expected actual
124 test_expect_success 'Checking attributes in a non-XDG global attributes file' '
125 test_might_fail rm .gitattributes &&
126 echo "f attr_f=test" >"$HOME"/my_gitattributes &&
127 git config core.attributesfile "$HOME"/my_gitattributes &&
128 echo "f: attr_f: test" >expected &&
129 git check-attr -a f >actual &&
130 test_cmp expected actual
134 test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
135 mkdir -p "$HOME"/.config/git &&
136 >"$HOME"/.config/git/config &&
137 test_might_fail rm "$HOME"/.gitconfig &&
138 git config --global user.name "write_config" &&
139 echo "[user]" >expected &&
140 echo " name = write_config" >>expected &&
141 test_cmp expected "$HOME"/.config/git/config
145 test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
146 >"$HOME"/.gitconfig &&
147 git config --global user.name "write_gitconfig" &&
148 echo "[user]" >expected &&
149 echo " name = write_gitconfig" >>expected &&
150 test_cmp expected "$HOME"/.gitconfig
154 test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
155 test_might_fail rm "$HOME"/.gitconfig &&
156 test_might_fail rm "$HOME"/.config/git/config &&
157 git config --global user.name "write_gitconfig" &&
158 echo "[user]" >expected &&
159 echo " name = write_gitconfig" >>expected &&
160 test_cmp expected "$HOME"/.gitconfig
164 test_done