Skip to content

Commit 91c031d

Browse files
jrngitster
authored andcommitted
tests: cosmetic improvements to the repo-setup test
Give an overview in "sh t1510-repo-setup.sh --help" output. Waste some vertical and horizontal space for clearer code. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95b104c commit 91c031d

File tree

1 file changed

+50
-44
lines changed

1 file changed

+50
-44
lines changed

t/t1510-repo-setup.sh

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
11
#!/bin/sh
22

3-
test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
3+
test_description="Tests of cwd/prefix/worktree/gitdir setup in all cases
44
5-
. ./test-lib.sh
5+
A few rules for repo setup:
66
7-
#
8-
# A few rules for repo setup:
9-
#
10-
# 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
11-
# GIT_DIR.
12-
#
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.
16-
#
17-
# 3. core.worktree is relative to git_dir.
18-
#
19-
# 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
20-
# equivalent to GIT_WORK_TREE.
21-
#
22-
# 5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
23-
# Uneffective worktree settings should be warned.
24-
#
25-
# 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
26-
#
27-
# 7. Effective core.worktree conflicts with core.bare
28-
#
29-
# 8. If GIT_DIR is set but neither worktree nor bare setting is given,
30-
# original cwd becomes worktree.
31-
#
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.
34-
#
35-
# 10. If no worktree is available, cwd remains unchanged, prefix is
36-
# NULL.
37-
#
38-
# 11. When user's cwd is outside worktree, cwd remains unchanged,
39-
# prefix is NULL.
40-
#
7+
1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
8+
GIT_DIR.
9+
10+
2. .git file is relative to parent directory. .git file is basically
11+
symlink in disguise. The directory where .git file points to will
12+
become new git_dir.
13+
14+
3. core.worktree is relative to git_dir.
15+
16+
4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
17+
equivalent to GIT_WORK_TREE.
18+
19+
5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
20+
Uneffective worktree settings should be warned.
21+
22+
6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
23+
24+
7. Effective core.worktree conflicts with core.bare
25+
26+
8. If GIT_DIR is set but neither worktree nor bare setting is given,
27+
original cwd becomes worktree.
28+
29+
9. If .git discovery is done inside a repo, the repo becomes a bare
30+
repo. .git discovery is performed if GIT_DIR is not set.
31+
32+
10. If no worktree is available, cwd remains unchanged, prefix is
33+
NULL.
34+
35+
11. When user's cwd is outside worktree, cwd remains unchanged,
36+
prefix is NULL.
37+
"
38+
. ./test-lib.sh
4139

42-
test_repo() {
40+
test_repo () {
4341
(
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
42+
cd "$1" &&
43+
if test -n "$2"
44+
then
45+
GIT_DIR="$2" &&
46+
export GIT_DIR
47+
fi &&
48+
if test -n "$3"
49+
then
50+
GIT_WORK_TREE="$3" &&
51+
export GIT_WORK_TREE
52+
fi &&
53+
rm -f trace &&
54+
GIT_TRACE="$(pwd)/trace" git symbolic-ref HEAD >/dev/null &&
55+
grep '^setup: ' trace >result &&
56+
test_cmp expected result
5157
)
5258
}
5359

0 commit comments

Comments
 (0)