t1510: setup case #0
[git.git] / t / t1510-repo-setup.sh
blob26842274a22b7bd949de5f8d0090a2e6200bb5ee
1 #!/bin/sh
3 test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
5 . ./test-lib.sh
8 # A few rules for repo setup:
10 # 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
11 # GIT_DIR.
13 # 2. .git file is relative to parent directory. .git file is basically
14 # symlink in disguise. The directory where .git file points to will
15 # become new git_dir.
17 # 3. core.worktree is relative to git_dir.
19 # 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
20 # equivalent to GIT_WORK_TREE.
22 # 5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
23 # Uneffective worktree settings should be warned.
25 # 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
27 # 7. Effective core.worktree conflicts with core.bare
29 # 8. If GIT_DIR is set but neither worktree nor bare setting is given,
30 # original cwd becomes worktree.
32 # 9. If .git discovery is done inside a repo, the repo becomes a bare
33 # repo. .git discovery is performed if GIT_DIR is not set.
35 # 10. If no worktree is available, cwd remains unchanged, prefix is
36 # NULL.
38 # 11. When user's cwd is outside worktree, cwd remains unchanged,
39 # prefix is NULL.
42 test_repo() {
44 cd "$1" &&
45 if test -n "$2"; then GIT_DIR="$2" && export GIT_DIR; fi &&
46 if test -n "$3"; then GIT_WORK_TREE="$3" && export GIT_WORK_TREE; fi &&
47 rm -f trace &&
48 GIT_TRACE="`pwd`/trace" git symbolic-ref HEAD >/dev/null &&
49 grep '^setup: ' trace >result &&
50 test_cmp expected result
54 # Bit 0 = GIT_WORK_TREE
55 # Bit 1 = GIT_DIR
56 # Bit 2 = core.worktree
57 # Bit 3 = .git is a file
58 # Bit 4 = bare repo
59 # Case# = encoding of the above 5 bits
62 # Case #0
64 ############################################################
66 # Input:
68 # - GIT_WORK_TREE is not set
69 # - GIT_DIR is not set
70 # - core.worktree is not set
71 # - .git is a directory
72 # - core.bare is not set, cwd is outside .git
74 # Output:
76 # - worktree is .git's parent directory
77 # - cwd is at worktree root dir
78 # - prefix is calculated
79 # - git_dir is set to ".git"
80 # - cwd can't be outside worktree
82 test_expect_success '#0: setup' '
83 unset GIT_DIR GIT_WORK_TREE &&
84 mkdir 0 0/sub &&
85 cd 0 && git init && cd ..
88 test_expect_success '#0: at root' '
89 cat >0/expected <<EOF &&
90 setup: git_dir: .git
91 setup: worktree: $TRASH_DIRECTORY/0
92 setup: cwd: $TRASH_DIRECTORY/0
93 setup: prefix: (null)
94 EOF
95 test_repo 0
98 test_expect_success '#0: in subdir' '
99 cat >0/sub/expected <<EOF &&
100 setup: git_dir: .git
101 setup: worktree: $TRASH_DIRECTORY/0
102 setup: cwd: $TRASH_DIRECTORY/0
103 setup: prefix: sub/
105 test_repo 0/sub
108 test_done