3 test_description
='behavior of diff when reading objects in a partial clone'
7 test_expect_success
'git show batches blobs' '
8 test_when_finished "rm -rf server client trace" &&
10 test_create_repo server &&
13 git -C server add a b &&
14 git -C server commit -m x &&
16 test_config -C server uploadpack.allowfilter 1 &&
17 test_config -C server uploadpack.allowanysha1inwant 1 &&
18 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
20 # Ensure that there is exactly 1 negotiation by checking that there is
21 # only 1 "done" line sent. ("done" marks the end of negotiation.)
22 GIT_TRACE_PACKET="$(pwd)/trace" git -C client show HEAD &&
23 grep "git> done" trace >done_lines &&
24 test_line_count = 1 done_lines
27 test_expect_success
'diff batches blobs' '
28 test_when_finished "rm -rf server client trace" &&
30 test_create_repo server &&
33 git -C server add a b &&
34 git -C server commit -m x &&
37 git -C server add c d &&
38 git -C server commit -m x &&
40 test_config -C server uploadpack.allowfilter 1 &&
41 test_config -C server uploadpack.allowanysha1inwant 1 &&
42 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
44 # Ensure that there is exactly 1 negotiation by checking that there is
45 # only 1 "done" line sent. ("done" marks the end of negotiation.)
46 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD &&
47 grep "git> done" trace >done_lines &&
48 test_line_count = 1 done_lines
51 test_expect_success
'diff skips same-OID blobs' '
52 test_when_finished "rm -rf server client trace" &&
54 test_create_repo server &&
57 git -C server add a b &&
58 git -C server commit -m x &&
59 echo another-a >server/a &&
60 git -C server add a &&
61 git -C server commit -m x &&
63 test_config -C server uploadpack.allowfilter 1 &&
64 test_config -C server uploadpack.allowanysha1inwant 1 &&
65 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
67 echo a | git hash-object --stdin >hash-old-a &&
68 echo another-a | git hash-object --stdin >hash-new-a &&
69 echo b | git hash-object --stdin >hash-b &&
71 # Ensure that only a and another-a are fetched.
72 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD &&
73 grep "want $(cat hash-old-a)" trace &&
74 grep "want $(cat hash-new-a)" trace &&
75 ! grep "want $(cat hash-b)" trace
78 test_expect_success
'when fetching missing objects, diff skips GITLINKs' '
79 test_when_finished "rm -rf sub server client trace" &&
81 test_create_repo sub &&
82 test_commit -C sub first &&
84 test_create_repo server &&
86 git -C server add a &&
87 git -C server submodule add "file://$(pwd)/sub" &&
88 git -C server commit -m x &&
90 test_commit -C server/sub second &&
91 echo another-a >server/a &&
92 git -C server add a sub &&
93 git -C server commit -m x &&
95 test_config -C server uploadpack.allowfilter 1 &&
96 test_config -C server uploadpack.allowanysha1inwant 1 &&
97 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
99 echo a | git hash-object --stdin >hash-old-a &&
100 echo another-a | git hash-object --stdin >hash-new-a &&
102 # Ensure that a and another-a are fetched, and check (by successful
103 # execution of the diff) that no invalid OIDs are sent.
104 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD &&
105 grep "want $(cat hash-old-a)" trace &&
106 grep "want $(cat hash-new-a)" trace
109 test_expect_success
'diff with rename detection batches blobs' '
110 test_when_finished "rm -rf server client trace" &&
112 test_create_repo server &&
114 printf "b\nb\nb\nb\nb\n" >server/b &&
115 git -C server add a b &&
116 git -C server commit -m x &&
118 printf "b\nb\nb\nb\nbX\n" >server/c &&
119 git -C server add c &&
120 git -C server commit -a -m x &&
122 test_config -C server uploadpack.allowfilter 1 &&
123 test_config -C server uploadpack.allowanysha1inwant 1 &&
124 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
126 # Ensure that there is exactly 1 negotiation by checking that there is
127 # only 1 "done" line sent. ("done" marks the end of negotiation.)
128 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD >out &&
129 grep ":100644 100644.*R[0-9][0-9][0-9].*b.*c" out &&
130 grep "git> done" trace >done_lines &&
131 test_line_count = 1 done_lines
134 test_expect_success
'diff does not fetch anything if inexact rename detection is not needed' '
135 test_when_finished "rm -rf server client trace" &&
137 test_create_repo server &&
139 printf "b\nb\nb\nb\nb\n" >server/b &&
140 git -C server add a b &&
141 git -C server commit -m x &&
142 mv server/b server/c &&
143 git -C server add c &&
144 git -C server commit -a -m x &&
146 test_config -C server uploadpack.allowfilter 1 &&
147 test_config -C server uploadpack.allowanysha1inwant 1 &&
148 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
151 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD &&
152 ! test_path_exists trace
155 test_expect_success
'diff --break-rewrites fetches only if necessary, and batches blobs if it does' '
156 test_when_finished "rm -rf server client trace" &&
158 test_create_repo server &&
160 printf "b\nb\nb\nb\nb\n" >server/b &&
161 git -C server add a b &&
162 git -C server commit -m x &&
163 printf "c\nc\nc\nc\nc\n" >server/b &&
164 git -C server commit -a -m x &&
166 test_config -C server uploadpack.allowfilter 1 &&
167 test_config -C server uploadpack.allowanysha1inwant 1 &&
168 git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
171 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD &&
172 ! test_path_exists trace &&
174 # But with --break-rewrites, ensure that there is exactly 1 negotiation
175 # by checking that there is only 1 "done" line sent. ("done" marks the
176 # end of negotiation.)
177 GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --break-rewrites --raw -M HEAD^ HEAD &&
178 grep "git> done" trace >done_lines &&
179 test_line_count = 1 done_lines