scalar-clone: add test coverage
Create a new test file ('t9211-scalar-clone.sh') to exercise the options and behavior of the 'scalar clone' command. Each test clones to a unique target location and cleans up the cloned repo only when the test passes. This ensures that failed tests' artifacts are captured in CI artifacts for further debugging. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Victoria Dye committed
Sep 2, 2022 at 15:56 UTC
14b4e7e5a455b771f9dee74a5b4eb9a10f2a1cd4
1 file changed
+151
t/t9211-scalar-clone.sh
new
+151
@@ -0,0 +1,151 @@
1
+#!/bin/sh
2
+
3
+test_description='test the `scalar clone` subcommand'
4
+
5
+. ./test-lib.sh
6
+
7
+GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
8
+export GIT_TEST_MAINT_SCHEDULER
9
+
10
+test_expect_success 'set up repository to clone' '
11
+ rm -rf .git &&
12
+ git init to-clone &&
13
+ (
14
+ cd to-clone &&
15
+ git branch -m base &&
16
+
17
+ test_commit first &&
18
+ test_commit second &&
19
+ test_commit third &&
20
+
21
+ git switch -c parallel first &&
22
+ mkdir -p 1/2 &&
23
+ test_commit 1/2/3 &&
24
+
25
+ git switch base &&
26
+
27
+ # By default, permit
28
+ git config uploadpack.allowfilter true &&
29
+ git config uploadpack.allowanysha1inwant true
30
+ )
31
+'
32
+
33
+cleanup_clone () {
34
+ rm -rf "$1"
35
+}
36
+
37
+test_expect_success 'creates content in enlistment root' '
38
+ enlistment=cloned &&
39
+
40
+ scalar clone "file://$(pwd)/to-clone" $enlistment &&
41
+ ls -A $enlistment >enlistment-root &&
42
+ test_line_count = 1 enlistment-root &&
43
+ test_path_is_dir $enlistment/src &&
44
+ test_path_is_dir $enlistment/src/.git &&
45
+
46
+ cleanup_clone $enlistment
47
+'
48
+
49
+test_expect_success 'with spaces' '
50
+ enlistment="cloned with space" &&
51
+
52
+ scalar clone "file://$(pwd)/to-clone" "$enlistment" &&
53
+ test_path_is_dir "$enlistment" &&
54
+ test_path_is_dir "$enlistment/src" &&
55
+ test_path_is_dir "$enlistment/src/.git" &&
56
+
57
+ cleanup_clone "$enlistment"
58
+'
59
+
60
+test_expect_success 'partial clone if supported by server' '
61
+ enlistment=partial-clone &&
62
+
63
+ scalar clone "file://$(pwd)/to-clone" $enlistment &&
64
+
65
+ (
66
+ cd $enlistment/src &&
67
+
68
+ # Two promisor packs: one for refs, the other for blobs
69
+ ls .git/objects/pack/pack-*.promisor >promisorlist &&
70
+ test_line_count = 2 promisorlist
71
+ ) &&
72
+
73
+ cleanup_clone $enlistment
74
+'
75
+
76
+test_expect_success 'fall back on full clone if partial unsupported' '
77
+ enlistment=no-partial-support &&
78
+
79
+ test_config -C to-clone uploadpack.allowfilter false &&
80
+ test_config -C to-clone uploadpack.allowanysha1inwant false &&
81
+
82
+ scalar clone "file://$(pwd)/to-clone" $enlistment 2>err &&
83
+ grep "filtering not recognized by server, ignoring" err &&
84
+
85
+ (
86
+ cd $enlistment/src &&
87
+
88
+ # Still get a refs promisor file, but none for blobs
89
+ ls .git/objects/pack/pack-*.promisor >promisorlist &&
90
+ test_line_count = 1 promisorlist
91
+ ) &&
92
+
93
+ cleanup_clone $enlistment
94
+'
95
+
96
+test_expect_success 'initializes sparse-checkout by default' '
97
+ enlistment=sparse &&
98
+
99
+ scalar clone "file://$(pwd)/to-clone" $enlistment &&
100
+ (
101
+ cd $enlistment/src &&
102
+ test_cmp_config true core.sparseCheckout &&
103
+ test_cmp_config true core.sparseCheckoutCone
104
+ ) &&
105
+
106
+ cleanup_clone $enlistment
107
+'
108
+
109
+test_expect_success '--full-clone does not create sparse-checkout' '
110
+ enlistment=full-clone &&
111
+
112
+ scalar clone --full-clone "file://$(pwd)/to-clone" $enlistment &&
113
+ (
114
+ cd $enlistment/src &&
115
+ test_cmp_config "" --default "" core.sparseCheckout &&
116
+ test_cmp_config "" --default "" core.sparseCheckoutCone
117
+ ) &&
118
+
119
+ cleanup_clone $enlistment
120
+'
121
+
122
+test_expect_success '--single-branch clones HEAD only' '
123
+ enlistment=single-branch &&
124
+
125
+ scalar clone --single-branch "file://$(pwd)/to-clone" $enlistment &&
126
+ (
127
+ cd $enlistment/src &&
128
+ git for-each-ref refs/remotes/origin >out &&
129
+ test_line_count = 1 out &&
130
+ grep "refs/remotes/origin/base" out
131
+ ) &&
132
+
133
+ cleanup_clone $enlistment
134
+'
135
+
136
+test_expect_success '--no-single-branch clones all branches' '
137
+ enlistment=no-single-branch &&
138
+
139
+ scalar clone --no-single-branch "file://$(pwd)/to-clone" $enlistment &&
140
+ (
141
+ cd $enlistment/src &&
142
+ git for-each-ref refs/remotes/origin >out &&
143
+ test_line_count = 2 out &&
144
+ grep "refs/remotes/origin/base" out &&
145
+ grep "refs/remotes/origin/parallel" out
146
+ ) &&
147
+
148
+ cleanup_clone $enlistment
149
+'
150
+
151
+test_done