git-clone: remove leftover debugging fprintf().
[git/git-bigfiles.git] / t / t1501-worktree.sh
blob2ee88d8a069288d0d9f6931231162e04d6b0917a
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 GIT_DIR=repo.git
36 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
37 export GIT_DIR GIT_CONFIG
38 unset GIT_WORK_TREE
39 git config core.worktree ../work
40 test_rev_parse 'outside' false false false
41 cd work || exit 1
42 GIT_DIR=../repo.git
43 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
44 test_rev_parse 'inside' false false true ''
45 cd sub/dir || exit 1
46 GIT_DIR=../../../repo.git
47 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
48 test_rev_parse 'subdirectory' false false true sub/dir/
49 cd ../../.. || exit 1
51 say "core.worktree = absolute path"
52 GIT_DIR=$(pwd)/repo.git
53 GIT_CONFIG=$GIT_DIR/config
54 git config core.worktree "$(pwd)/work"
55 test_rev_parse 'outside' false false false
56 cd work || exit 1
57 test_rev_parse 'inside' false false true ''
58 cd sub/dir || exit 1
59 test_rev_parse 'subdirectory' false false true sub/dir/
60 cd ../../.. || exit 1
62 say "GIT_WORK_TREE=relative path (override core.worktree)"
63 GIT_DIR=$(pwd)/repo.git
64 GIT_CONFIG=$GIT_DIR/config
65 git config core.worktree non-existent
66 GIT_WORK_TREE=work
67 export GIT_WORK_TREE
68 test_rev_parse 'outside' false false false
69 cd work || exit 1
70 GIT_WORK_TREE=.
71 test_rev_parse 'inside' false false true ''
72 cd sub/dir || exit 1
73 GIT_WORK_TREE=../..
74 test_rev_parse 'subdirectory' false false true sub/dir/
75 cd ../../.. || exit 1
77 mv work repo.git/work
79 say "GIT_WORK_TREE=absolute path, work tree below git dir"
80 GIT_DIR=$(pwd)/repo.git
81 GIT_CONFIG=$GIT_DIR/config
82 GIT_WORK_TREE=$(pwd)/repo.git/work
83 test_rev_parse 'outside' false false false
84 cd repo.git || exit 1
85 test_rev_parse 'in repo.git' false true false
86 cd objects || exit 1
87 test_rev_parse 'in repo.git/objects' false true false
88 cd ../work || exit 1
89 test_rev_parse 'in repo.git/work' false true true ''
90 cd sub/dir || exit 1
91 test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
92 cd ../../../.. || exit 1
94 test_expect_success 'repo finds its work tree' '
95 (cd repo.git &&
96 : > work/sub/dir/untracked &&
97 test sub/dir/untracked = "$(git ls-files --others)")
100 test_expect_success 'repo finds its work tree from work tree, too' '
101 (cd repo.git/work/sub/dir &&
102 : > tracked &&
103 git --git-dir=../../.. add tracked &&
104 cd ../../.. &&
105 test sub/dir/tracked = "$(git ls-files)")
108 test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
109 cd repo.git/work/sub/dir &&
110 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
111 git diff --exit-code tracked &&
112 echo changed > tracked &&
113 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
114 git diff --exit-code tracked
117 test_done