]>
Commit | Line | Data |
---|---|---|
7fbbcb21 JT |
1 | #!/bin/sh |
2 | ||
3 | test_description='behavior of diff when reading objects in a partial clone' | |
4 | ||
dd4143e7 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
7fbbcb21 JT |
6 | . ./test-lib.sh |
7 | ||
8 | test_expect_success 'git show batches blobs' ' | |
9 | test_when_finished "rm -rf server client trace" && | |
10 | ||
11 | test_create_repo server && | |
12 | echo a >server/a && | |
13 | echo b >server/b && | |
14 | git -C server add a b && | |
15 | git -C server commit -m x && | |
16 | ||
17 | test_config -C server uploadpack.allowfilter 1 && | |
18 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
19 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
20 | ||
21 | # Ensure that there is exactly 1 negotiation by checking that there is | |
22 | # only 1 "done" line sent. ("done" marks the end of negotiation.) | |
23 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client show HEAD && | |
7ca3c0ac | 24 | grep "fetch> done" trace >done_lines && |
7fbbcb21 JT |
25 | test_line_count = 1 done_lines |
26 | ' | |
27 | ||
28 | test_expect_success 'diff batches blobs' ' | |
29 | test_when_finished "rm -rf server client trace" && | |
30 | ||
31 | test_create_repo server && | |
32 | echo a >server/a && | |
33 | echo b >server/b && | |
34 | git -C server add a b && | |
35 | git -C server commit -m x && | |
36 | echo c >server/c && | |
37 | echo d >server/d && | |
38 | git -C server add c d && | |
39 | git -C server commit -m x && | |
40 | ||
41 | test_config -C server uploadpack.allowfilter 1 && | |
42 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
43 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
44 | ||
45 | # Ensure that there is exactly 1 negotiation by checking that there is | |
46 | # only 1 "done" line sent. ("done" marks the end of negotiation.) | |
47 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && | |
7ca3c0ac | 48 | grep "fetch> done" trace >done_lines && |
7fbbcb21 JT |
49 | test_line_count = 1 done_lines |
50 | ' | |
51 | ||
52 | test_expect_success 'diff skips same-OID blobs' ' | |
53 | test_when_finished "rm -rf server client trace" && | |
54 | ||
55 | test_create_repo server && | |
56 | echo a >server/a && | |
57 | echo b >server/b && | |
58 | git -C server add a b && | |
59 | git -C server commit -m x && | |
60 | echo another-a >server/a && | |
61 | git -C server add a && | |
62 | git -C server commit -m x && | |
63 | ||
64 | test_config -C server uploadpack.allowfilter 1 && | |
65 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
66 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
67 | ||
68 | echo a | git hash-object --stdin >hash-old-a && | |
69 | echo another-a | git hash-object --stdin >hash-new-a && | |
70 | echo b | git hash-object --stdin >hash-b && | |
71 | ||
72 | # Ensure that only a and another-a are fetched. | |
73 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && | |
74 | grep "want $(cat hash-old-a)" trace && | |
75 | grep "want $(cat hash-new-a)" trace && | |
76 | ! grep "want $(cat hash-b)" trace | |
77 | ' | |
78 | ||
a63694f5 JT |
79 | test_expect_success 'when fetching missing objects, diff skips GITLINKs' ' |
80 | test_when_finished "rm -rf sub server client trace" && | |
ac7e57fa | 81 | test_config_global protocol.file.allow always && |
a63694f5 JT |
82 | |
83 | test_create_repo sub && | |
84 | test_commit -C sub first && | |
85 | ||
86 | test_create_repo server && | |
87 | echo a >server/a && | |
88 | git -C server add a && | |
89 | git -C server submodule add "file://$(pwd)/sub" && | |
90 | git -C server commit -m x && | |
91 | ||
92 | test_commit -C server/sub second && | |
93 | echo another-a >server/a && | |
94 | git -C server add a sub && | |
95 | git -C server commit -m x && | |
96 | ||
97 | test_config -C server uploadpack.allowfilter 1 && | |
98 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
99 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
100 | ||
101 | echo a | git hash-object --stdin >hash-old-a && | |
102 | echo another-a | git hash-object --stdin >hash-new-a && | |
103 | ||
104 | # Ensure that a and another-a are fetched, and check (by successful | |
105 | # execution of the diff) that no invalid OIDs are sent. | |
106 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && | |
107 | grep "want $(cat hash-old-a)" trace && | |
108 | grep "want $(cat hash-new-a)" trace | |
109 | ' | |
110 | ||
7fbbcb21 JT |
111 | test_expect_success 'diff with rename detection batches blobs' ' |
112 | test_when_finished "rm -rf server client trace" && | |
113 | ||
114 | test_create_repo server && | |
115 | echo a >server/a && | |
116 | printf "b\nb\nb\nb\nb\n" >server/b && | |
117 | git -C server add a b && | |
118 | git -C server commit -m x && | |
119 | rm server/b && | |
120 | printf "b\nb\nb\nb\nbX\n" >server/c && | |
121 | git -C server add c && | |
122 | git -C server commit -a -m x && | |
123 | ||
124 | test_config -C server uploadpack.allowfilter 1 && | |
125 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
126 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
127 | ||
128 | # Ensure that there is exactly 1 negotiation by checking that there is | |
129 | # only 1 "done" line sent. ("done" marks the end of negotiation.) | |
293194c9 JT |
130 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD >out && |
131 | grep ":100644 100644.*R[0-9][0-9][0-9].*b.*c" out && | |
7ca3c0ac | 132 | grep "fetch> done" trace >done_lines && |
7fbbcb21 JT |
133 | test_line_count = 1 done_lines |
134 | ' | |
135 | ||
95acf11a JT |
136 | test_expect_success 'diff does not fetch anything if inexact rename detection is not needed' ' |
137 | test_when_finished "rm -rf server client trace" && | |
138 | ||
139 | test_create_repo server && | |
140 | echo a >server/a && | |
141 | printf "b\nb\nb\nb\nb\n" >server/b && | |
142 | git -C server add a b && | |
143 | git -C server commit -m x && | |
144 | mv server/b server/c && | |
145 | git -C server add c && | |
146 | git -C server commit -a -m x && | |
147 | ||
148 | test_config -C server uploadpack.allowfilter 1 && | |
149 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
150 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
151 | ||
152 | # Ensure no fetches. | |
153 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && | |
c2059236 | 154 | test_path_is_missing trace |
95acf11a JT |
155 | ' |
156 | ||
157 | test_expect_success 'diff --break-rewrites fetches only if necessary, and batches blobs if it does' ' | |
158 | test_when_finished "rm -rf server client trace" && | |
159 | ||
160 | test_create_repo server && | |
161 | echo a >server/a && | |
162 | printf "b\nb\nb\nb\nb\n" >server/b && | |
163 | git -C server add a b && | |
164 | git -C server commit -m x && | |
165 | printf "c\nc\nc\nc\nc\n" >server/b && | |
166 | git -C server commit -a -m x && | |
167 | ||
168 | test_config -C server uploadpack.allowfilter 1 && | |
169 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
170 | git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && | |
171 | ||
172 | # Ensure no fetches. | |
173 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && | |
c2059236 | 174 | test_path_is_missing trace && |
95acf11a JT |
175 | |
176 | # But with --break-rewrites, ensure that there is exactly 1 negotiation | |
177 | # by checking that there is only 1 "done" line sent. ("done" marks the | |
178 | # end of negotiation.) | |
179 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --break-rewrites --raw -M HEAD^ HEAD && | |
7ca3c0ac | 180 | grep "fetch> done" trace >done_lines && |
95acf11a JT |
181 | test_line_count = 1 done_lines |
182 | ' | |
183 | ||
7fbbcb21 | 184 | test_done |