t5613: do not chdir in main process
Our usual style when working with subdirectories is to chdir inside a subshell or to use "git -C", which means we do not have to constantly return to the main test directory. Let's convert this old test, which does not follow that style. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 3, 2016 at 16:34 UTC
8f2ed2675358a6e6543f962f6e1b3ec0737e8079
1 file changed
+33
-59
t/t5613-info-alternate.sh
+33
-59
@@ -6,44 +6,39 @@
6
test_description='test transitive info/alternate entries'
7
. ./test-lib.sh
8
9
-base_dir=$(pwd)
10
-
9
test_expect_success 'preparing first repository' '
12
- test_create_repo A &&
13
- cd A &&
14
- echo "Hello World" > file1 &&
15
- git add file1 &&
16
- git commit -m "Initial commit" file1 &&
17
- git repack -a -d &&
18
- git prune
10
+ test_create_repo A && (
11
+ cd A &&
12
+ echo "Hello World" > file1 &&
13
+ git add file1 &&
14
+ git commit -m "Initial commit" file1 &&
15
+ git repack -a -d &&
16
+ git prune
17
+ )
18
'
19
21
-cd "$base_dir"
22
-
20
test_expect_success 'preparing second repository' '
24
- git clone -l -s A B &&
25
- cd B &&
26
- echo "foo bar" > file2 &&
27
- git add file2 &&
28
- git commit -m "next commit" file2 &&
29
- git repack -a -d -l &&
30
- git prune
21
+ git clone -l -s A B && (
22
+ cd B &&
23
+ echo "foo bar" > file2 &&
24
+ git add file2 &&
25
+ git commit -m "next commit" file2 &&
26
+ git repack -a -d -l &&
27
+ git prune
28
+ )
29
'
30
33
-cd "$base_dir"
34
-
31
test_expect_success 'preparing third repository' '
36
- git clone -l -s B C &&
37
- cd C &&
38
- echo "Goodbye, cruel world" > file3 &&
39
- git add file3 &&
40
- git commit -m "one more" file3 &&
41
- git repack -a -d -l &&
42
- git prune
32
+ git clone -l -s B C && (
33
+ cd C &&
34
+ echo "Goodbye, cruel world" > file3 &&
35
+ git add file3 &&
36
+ git commit -m "one more" file3 &&
37
+ git repack -a -d -l &&
38
+ git prune
39
+ )
40
'
41
45
-cd "$base_dir"
46
-
42
test_expect_success 'creating too deep nesting' '
43
git clone -l -s C D &&
44
git clone -l -s D E &&
@@ -53,55 +48,34 @@ test_expect_success 'creating too deep nesting' '
48
'
49
50
test_expect_success 'invalidity of deepest repository' '
56
- cd H &&
57
- test_must_fail git fsck
51
+ test_must_fail git -C H fsck
52
'
53
60
-cd "$base_dir"
61
-
54
test_expect_success 'validity of third repository' '
63
- cd C &&
64
- git fsck
55
+ git -C C fsck
56
'
57
67
-cd "$base_dir"
68
-
58
test_expect_success 'validity of fourth repository' '
70
- cd D &&
71
- git fsck
59
+ git -C D fsck
60
'
61
74
-cd "$base_dir"
75
-
62
test_expect_success 'breaking of loops' '
77
- echo "$base_dir"/B/.git/objects >>"$base_dir"/A/.git/objects/info/alternatesi &&
78
- cd C &&
79
- git fsck
63
+ echo "$(pwd)"/B/.git/objects >>A/.git/objects/info/alternates &&
64
+ git -C C fsck
65
'
66
82
-cd "$base_dir"
83
-
67
test_expect_success 'that info/alternates is necessary' '
85
- cd C &&
86
- rm -f .git/objects/info/alternates &&
87
- test_must_fail git fsck
68
+ rm -f C/.git/objects/info/alternates &&
69
+ test_must_fail git -C C fsck
70
'
71
90
-cd "$base_dir"
91
-
72
test_expect_success 'that relative alternate is possible for current dir' '
93
- cd C &&
94
- echo "../../../B/.git/objects" > .git/objects/info/alternates &&
73
+ echo "../../../B/.git/objects" >C/.git/objects/info/alternates &&
74
git fsck
75
'
76
98
-cd "$base_dir"
99
-
77
test_expect_success 'that relative alternate is only possible for current dir' '
101
- cd D &&
102
- test_must_fail git fsck
78
+ test_must_fail git -C D fsck
79
'
80
105
-cd "$base_dir"
106
-
81
test_done