Skip to content

Commit 9292536

Browse files
stefanbellergitster
authored andcommitted
t7408: merge short tests, factor out testing method
Tests consisting of one line each can be consolidated to have fewer tests to run as well as fewer lines of code. When having just a few git commands, do not create a new shell but use the -C flag in Git to execute in the correct directory. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83dec73 commit 9292536

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

t/t7408-submodule-reference.sh

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ test_description='test clone --reference'
88

99
base_dir=$(pwd)
1010

11+
test_alternate_is_used () {
12+
alternates_file="$1" &&
13+
working_dir="$2" &&
14+
test_line_count = 1 "$alternates_file" &&
15+
echo "0 objects, 0 kilobytes" >expect &&
16+
git -C "$working_dir" count-objects >actual &&
17+
test_cmp expect actual
18+
}
19+
1120
test_expect_success 'preparing first repository' '
1221
test_create_repo A &&
1322
(
@@ -40,16 +49,14 @@ test_expect_success 'preparing superproject' '
4049
)
4150
'
4251

43-
test_expect_success 'submodule add --reference' '
52+
test_expect_success 'submodule add --reference uses alternates' '
4453
(
4554
cd super &&
4655
git submodule add --reference ../B "file://$base_dir/A" sub &&
47-
git commit -m B-super-added
48-
)
49-
'
50-
51-
test_expect_success 'after add: existence of info/alternates' '
52-
test_line_count = 1 super/.git/modules/sub/objects/info/alternates
56+
git commit -m B-super-added &&
57+
git repack -ad
58+
) &&
59+
test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
5360
'
5461

5562
test_expect_success 'that reference gets used with add' '
@@ -61,23 +68,18 @@ test_expect_success 'that reference gets used with add' '
6168
)
6269
'
6370

64-
test_expect_success 'cloning superproject' '
65-
git clone super super-clone
66-
'
67-
68-
test_expect_success 'update with reference' '
69-
cd super-clone && git submodule update --init --reference ../B
70-
'
71-
72-
test_expect_success 'after update: existence of info/alternates' '
73-
test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates
74-
'
71+
# The tests up to this point, and repositories created by them
72+
# (A, B, super and super/sub), are about setting up the stage
73+
# for subsequent tests and meant to be kept throughout the
74+
# remainder of the test.
75+
# Tests from here on, if they create their own test repository,
76+
# are expected to clean after themselves.
7577

76-
test_expect_success 'that reference gets used with update' '
77-
cd super-clone/sub &&
78-
echo "0 objects, 0 kilobytes" >expected &&
79-
git count-objects >current &&
80-
diff expected current
78+
test_expect_success 'updating superproject keeps alternates' '
79+
test_when_finished "rm -rf super-clone" &&
80+
git clone super super-clone &&
81+
git -C super-clone submodule update --init --reference ../B &&
82+
test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
8183
'
8284

8385
test_done

0 commit comments

Comments
 (0)