git-format-patch.txt: fix explanation of an example.
[git/mingw.git] / t / t1501-worktree.sh
blob7ee3820ce97b6c26c9465685a7bc64a962aad3cb
1 #!/bin/sh
3 test_description='test separate work tree'
4 . ./test-lib.sh
6 test_rev_parse() {
7 name=$1
8 shift
10 test_expect_success "$name: is-bare-repository" \
11 "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
12 shift
13 [ $# -eq 0 ] && return
15 test_expect_success "$name: is-inside-git-dir" \
16 "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
17 shift
18 [ $# -eq 0 ] && return
20 test_expect_success "$name: is-inside-work-tree" \
21 "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
22 shift
23 [ $# -eq 0 ] && return
25 test_expect_success "$name: prefix" \
26 "test '$1' = \"\$(git rev-parse --show-prefix)\""
27 shift
28 [ $# -eq 0 ] && return
31 mkdir -p work/sub/dir || exit 1
32 mv .git repo.git || exit 1
34 say "core.worktree = relative path"
35 export GIT_DIR=repo.git
36 export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
37 unset GIT_WORK_TREE
38 git config core.worktree ../work
39 test_rev_parse 'outside' false false false
40 cd work || exit 1
41 export GIT_DIR=../repo.git
42 export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
43 test_rev_parse 'inside' false false true ''
44 cd sub/dir || exit 1
45 export GIT_DIR=../../../repo.git
46 export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
47 test_rev_parse 'subdirectory' false false true sub/dir/
48 cd ../../.. || exit 1
50 say "core.worktree = absolute path"
51 export GIT_DIR=$(pwd)/repo.git
52 export GIT_CONFIG=$GIT_DIR/config
53 git config core.worktree "$(pwd)/work"
54 test_rev_parse 'outside' false false false
55 cd work || exit 1
56 test_rev_parse 'inside' false false true ''
57 cd sub/dir || exit 1
58 test_rev_parse 'subdirectory' false false true sub/dir/
59 cd ../../.. || exit 1
61 say "GIT_WORK_TREE=relative path (override core.worktree)"
62 export GIT_DIR=$(pwd)/repo.git
63 export GIT_CONFIG=$GIT_DIR/config
64 git config core.worktree non-existent
65 export GIT_WORK_TREE=work
66 test_rev_parse 'outside' false false false
67 cd work || exit 1
68 export GIT_WORK_TREE=.
69 test_rev_parse 'inside' false false true ''
70 cd sub/dir || exit 1
71 export GIT_WORK_TREE=../..
72 test_rev_parse 'subdirectory' false false true sub/dir/
73 cd ../../.. || exit 1
75 mv work repo.git/work
77 say "GIT_WORK_TREE=absolute path, work tree below git dir"
78 export GIT_DIR=$(pwd)/repo.git
79 export GIT_CONFIG=$GIT_DIR/config
80 export GIT_WORK_TREE=$(pwd)/repo.git/work
81 test_rev_parse 'outside' false false false
82 cd repo.git || exit 1
83 test_rev_parse 'in repo.git' false true false
84 cd objects || exit 1
85 test_rev_parse 'in repo.git/objects' false true false
86 cd ../work || exit 1
87 test_rev_parse 'in repo.git/work' false true true ''
88 cd sub/dir || exit 1
89 test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
90 cd ../../../.. || exit 1
92 test_expect_success 'repo finds its work tree' '
93 (cd repo.git &&
94 : > work/sub/dir/untracked &&
95 test sub/dir/untracked = "$(git ls-files --others)")
98 test_expect_success 'repo finds its work tree from work tree, too' '
99 (cd repo.git/work/sub/dir &&
100 : > tracked &&
101 git --git-dir=../../.. add tracked &&
102 cd ../../.. &&
103 test sub/dir/tracked = "$(git ls-files)")
106 test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
107 cd repo.git/work/sub/dir &&
108 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
109 git diff --exit-code tracked &&
110 echo changed > tracked &&
111 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
112 git diff --exit-code tracked
115 test_done