pretty-options.txt: tiny doc fix
[git/git-p4.git] / t / t1501-worktree.sh
blobaadeeab9ab38d96b63ae0bced02514d77d847e9f
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=$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=$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=$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 false true ''
88 cd sub/dir || exit 1
89 test_rev_parse 'in repo.git/sub/dir' false false true sub/dir/
90 cd ../../../.. || exit 1
92 test_done