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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 11, 2016 at 16:13 UTC
9292536eb40294507544b963538e738637f70e26
1 file changed
+25
-23
t/t7408-submodule-reference.sh
+25
-23
@@ -8,6 +8,15 @@ test_description='test clone --reference'
8
9
base_dir=$(pwd)
10
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
+
20
test_expect_success 'preparing first repository' '
21
test_create_repo A &&
22
(
@@ -40,16 +49,14 @@ test_expect_success 'preparing superproject' '
49
)
50
'
51
43
-test_expect_success 'submodule add --reference' '
52
+test_expect_success 'submodule add --reference uses alternates' '
53
(
54
cd super &&
55
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
60
'
61
62
test_expect_success 'that reference gets used with add' '
@@ -61,23 +68,18 @@ test_expect_success 'that reference gets used with add' '
68
)
69
'
70
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.
77
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
83
'
84
85
test_done