1#!/bin/sh
2#
3# Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4# Thomas Nguy, Khoi Nguyen
5# Grenoble INP Ensimag
6#
78
test_description='Compatibility with $XDG_CONFIG_HOME/git/ files'
910
. ./test-lib.sh
1112
test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '
13mkdir -p .config/git &&
14echo "[alias]" >.config/git/config &&
15echo " myalias = !echo in_config" >>.config/git/config &&
16echo in_config >expected &&
17git myalias >actual &&
18test_cmp expected actual
19'
2021
22
test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
23>.gitconfig &&
24echo "[alias]" >.gitconfig &&
25echo " myalias = !echo in_gitconfig" >>.gitconfig &&
26echo in_gitconfig >expected &&
27git myalias >actual &&
28test_cmp expected actual
29'
3031
32
test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
33rm .gitconfig &&
34echo "[user]" >.config/git/config &&
35echo " name = read_config" >>.config/git/config &&
36echo read_config >expected &&
37git config --get user.name >actual &&
38test_cmp expected actual
39'
4041
42
test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
43>.gitconfig &&
44echo "[user]" >.gitconfig &&
45echo " name = read_gitconfig" >>.gitconfig &&
46echo read_gitconfig >expected &&
47git config --get user.name >actual &&
48test_cmp expected actual
49'
5051
52
test_expect_success 'read with --list: xdg file exists and ~/.gitconfig doesn'\''t' '
53rm .gitconfig &&
54echo user.name=read_config >expected &&
55git config --global --list >actual &&
56test_cmp expected actual
57'
5859
60
test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists' '
61>.gitconfig &&
62echo "[user]" >.gitconfig &&
63echo " name = read_gitconfig" >>.gitconfig &&
64echo user.name=read_gitconfig >expected &&
65git config --global --list >actual &&
66test_cmp expected actual
67'
6869
70
test_expect_success 'Setup' '
71git init git &&
72cd git &&
73echo foo >to_be_excluded
74'
7576
77
test_expect_success 'Exclusion of a file in the XDG ignore file' '
78mkdir -p "$HOME"/.config/git/ &&
79echo to_be_excluded >"$HOME"/.config/git/ignore &&
80test_must_fail git add to_be_excluded
81'
8283
84
test_expect_success 'Exclusion in both XDG and local ignore files' '
85echo to_be_excluded >.gitignore &&
86test_must_fail git add to_be_excluded
87'
8889
90
test_expect_success 'Exclusion in a non-XDG global ignore file' '
91rm .gitignore &&
92echo >"$HOME"/.config/git/ignore &&
93echo to_be_excluded >"$HOME"/my_gitignore &&
94git config core.excludesfile "$HOME"/my_gitignore &&
95test_must_fail git add to_be_excluded
96'
9798
99
test_expect_success 'Checking attributes in the XDG attributes file' '
100echo foo >f &&
101git check-attr -a f >actual &&
102test_line_count -eq 0 actual &&
103echo "f attr_f" >"$HOME"/.config/git/attributes &&
104echo "f: attr_f: set" >expected &&
105git check-attr -a f >actual &&
106test_cmp expected actual
107'
108109
110
test_expect_success 'Checking attributes in both XDG and local attributes files' '
111echo "f -attr_f" >.gitattributes &&
112echo "f: attr_f: unset" >expected &&
113git check-attr -a f >actual &&
114test_cmp expected actual
115'
116117
118
test_expect_success 'Checking attributes in a non-XDG global attributes file' '
119test_might_fail rm .gitattributes &&
120echo "f attr_f=test" >"$HOME"/my_gitattributes &&
121git config core.attributesfile "$HOME"/my_gitattributes &&
122echo "f: attr_f: test" >expected &&
123git check-attr -a f >actual &&
124test_cmp expected actual
125'
126127
128
test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
129mkdir -p "$HOME"/.config/git &&
130>"$HOME"/.config/git/config &&
131test_might_fail rm "$HOME"/.gitconfig &&
132git config --global user.name "write_config" &&
133echo "[user]" >expected &&
134echo " name = write_config" >>expected &&
135test_cmp expected "$HOME"/.config/git/config
136'
137138
139
test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
140>"$HOME"/.gitconfig &&
141git config --global user.name "write_gitconfig" &&
142echo "[user]" >expected &&
143echo " name = write_gitconfig" >>expected &&
144test_cmp expected "$HOME"/.gitconfig
145'
146147
148
test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
149test_might_fail rm "$HOME"/.gitconfig &&
150test_might_fail rm "$HOME"/.config/git/config &&
151git config --global user.name "write_gitconfig" &&
152echo "[user]" >expected &&
153echo " name = write_gitconfig" >>expected &&
154test_cmp expected "$HOME"/.gitconfig
155'
156157
158
test_done