3
test_description='test config file include directives'
4
. ./test-lib.sh
5
6
+# Force setup_explicit_git_dir() to run until the end. This is needed
7
+# by some tests to make sure real_path() is called on $GIT_DIR. The
8
+# caller needs to make sure git commands are run from a subdirectory
9
+# though or real_path() will not be called.
10
+force_setup_explicit_git_dir() {
11
+ GIT_DIR="$(pwd)/.git"
12
+ GIT_WORK_TREE="$(pwd)"
13
+ export GIT_DIR GIT_WORK_TREE
14
+}
15
+
16
test_expect_success 'include file by absolute path' '
17
echo "[test]one = 1" >one &&
18
echo "[include]path = \"$(pwd)/one\"" >.gitconfig &&
218
)
219
'
220
221
+test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
222
+ mkdir real-home &&
223
+ ln -s real-home home &&
224
+ (
225
+ HOME="$TRASH_DIRECTORY/home" &&
226
+ export HOME &&
227
+ cd "$HOME" &&
228
+
229
+ git init foo &&
230
+ cd foo &&
231
+ mkdir sub
232
+ )
233
+'
234
+
235
+test_expect_success SYMLINKS 'conditional include, $HOME expansion with symlinks' '
236
+ (
237
+ HOME="$TRASH_DIRECTORY/home" &&
238
+ export HOME &&
239
+ cd "$HOME"/foo &&
240
+
241
+ echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config &&
242
+ echo "[test]two=2" >.git/bar2 &&
243
+ echo 2 >expect &&
244
+ force_setup_explicit_git_dir &&
245
+ git -C sub config test.two >actual &&
246
+ test_cmp expect actual
247
+ )
248
+'
249
+
250
+test_expect_success SYMLINKS 'conditional include, relative path with symlinks' '
251
+ echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >home/.gitconfig &&
252
+ echo "[test]four=4" >home/bar4 &&
253
+ (
254
+ HOME="$TRASH_DIRECTORY/home" &&
255
+ export HOME &&
256
+ cd "$HOME"/foo &&
257
+
258
+ echo 4 >expect &&
259
+ force_setup_explicit_git_dir &&
260
+ git -C sub config test.four >actual &&
261
+ test_cmp expect actual
262
+ )
263
+'
264
+
265
test_expect_success 'include cycles are detected' '
266
cat >.gitconfig <<-\EOF &&
267
[test]value = gitconfig