@@ -190,6 +190,8 @@ func (s *RemoteSuite) TestFetchWithDepth(c *C) {
190
190
plumbing .NewReferenceFromStrings ("refs/tags/v1.0.0" , "6ecf0ef2c2dffb796033e5a02219af86ec6584e5" ),
191
191
})
192
192
193
+ s .assertShallows (c , r , 2 )
194
+
193
195
c .Assert (r .s .(* memory.Storage ).Objects , HasLen , 18 )
194
196
}
195
197
@@ -203,10 +205,13 @@ func (s *RemoteSuite) TestFetchWithHashes(c *C) {
203
205
Hashes : []plumbing.Hash {
204
206
plumbing .NewHash ("6ecf0ef2c2dffb796033e5a02219af86ec6584e5" ),
205
207
},
208
+ Tags : NoTags ,
206
209
}, nil )
207
210
208
211
commits := r .s .(* memory.Storage ).Commits
209
212
c .Assert (commits , HasLen , 1 )
213
+
214
+ s .assertShallows (c , r , 1 )
210
215
}
211
216
212
217
func (s * RemoteSuite ) TestFetchWithHashesInShallow (c * C ) {
@@ -230,8 +235,11 @@ func (s *RemoteSuite) TestFetchWithHashesInShallow(c *C) {
230
235
Hashes : []plumbing.Hash {
231
236
headHash ,
232
237
},
238
+ Tags : NoTags ,
233
239
}, nil )
234
240
241
+ s .assertShallows (c , r , 1 )
242
+
235
243
// Control we did get it
236
244
commits := r .s .(* memory.Storage ).Commits
237
245
c .Assert (commits , HasLen , 1 )
@@ -241,19 +249,71 @@ func (s *RemoteSuite) TestFetchWithHashesInShallow(c *C) {
241
249
// We now fetch an older SHA
242
250
s .testFetch (c , r , & FetchOptions {
243
251
Depth : 1 ,
244
- RefSpecs : []config.RefSpec {
245
- config .RefSpec ("+refs/heads/master:refs/remotes/origin/master" ),
246
- },
247
252
Hashes : []plumbing.Hash {
248
253
olderHash ,
249
254
},
255
+ Tags : NoTags ,
250
256
}, nil )
251
257
252
258
// Control we did get it
253
259
commits = r .s .(* memory.Storage ).Commits
254
260
c .Assert (commits , HasLen , 2 )
255
261
_ , err = object .GetCommit (r .s , olderHash )
256
262
c .Assert (err , IsNil )
263
+
264
+ // NOTE: the server doesn't emit an `unshallow` packet line in
265
+ // this scenario, so it won't know to update the list of shallow
266
+ // commits. This is consistent with git cli.
267
+ s .assertShallows (c , r , 2 )
268
+ }
269
+
270
+ func (s * RemoteSuite ) TestFetchShallowBranchHeadThenFetchUnshallowBranch (c * C ) {
271
+ r := NewRemote (memory .NewStorage (), & config.RemoteConfig {
272
+ URLs : []string {s .GetBasicLocalRepositoryURL ()},
273
+ })
274
+
275
+ // We first need to set the right capabilities otherwise we can't fetch
276
+ // the commit we want
277
+ p := filepath .Join (r .c .URLs [0 ], "config" )
278
+ cfgCmd := exec .Command ("git" , "config" , "--file" , p , "--bool" , "uploadpack.allowAnySHA1InWant" , "true" )
279
+ err := cfgCmd .Run ()
280
+ c .Assert (err , IsNil )
281
+
282
+ headHash := plumbing .NewHash ("e8d3ffab552895c19b9fcf7aa264d277cde33881" )
283
+ firstHash := plumbing .NewHash ("b029517f6300c2da0f4b651b8642506cd6aaf45d" )
284
+
285
+ // We start by fetching the HEAD
286
+ s .testFetch (c , r , & FetchOptions {
287
+ Depth : 1 ,
288
+ Hashes : []plumbing.Hash {
289
+ headHash ,
290
+ },
291
+ }, nil )
292
+
293
+ // Control we did get it
294
+ commits := r .s .(* memory.Storage ).Commits
295
+ c .Assert (commits , HasLen , 1 )
296
+ _ , err = object .GetCommit (r .s , headHash )
297
+ c .Assert (err , IsNil )
298
+
299
+ // Fetch the branch where our shallow commit is the head of the branch
300
+ s .testFetch (c , r , & FetchOptions {
301
+ Depth : 2147483647 ,
302
+ RefSpecs : []config.RefSpec {
303
+ config .RefSpec ("+refs/heads/branch:refs/remotes/origin/branch" ),
304
+ },
305
+ }, []* plumbing.Reference {
306
+ plumbing .NewReferenceFromStrings ("refs/remotes/origin/branch" , headHash .String ()),
307
+ })
308
+
309
+ // Control we did get it
310
+ commits = r .s .(* memory.Storage ).Commits
311
+ totalCommitsInBranch := 8 // SEE: https://github.com/git-fixtures/basic/commits/branch
312
+ c .Assert (len (commits ), Equals , totalCommitsInBranch )
313
+ _ , err = object .GetCommit (r .s , firstHash )
314
+ c .Assert (err , IsNil )
315
+
316
+ s .assertShallows (c , r , 0 )
257
317
}
258
318
259
319
func (s * RemoteSuite ) TestFetchWithHashesDepthOfTwo (c * C ) {
@@ -268,6 +328,7 @@ func (s *RemoteSuite) TestFetchWithHashesDepthOfTwo(c *C) {
268
328
Hashes : []plumbing.Hash {
269
329
hash ,
270
330
},
331
+ Tags : NoTags ,
271
332
}, nil )
272
333
273
334
commits := r .s .(* memory.Storage ).Commits
@@ -291,6 +352,8 @@ func (s *RemoteSuite) TestFetchWithHashesDepthOfTwo(c *C) {
291
352
292
353
c .Assert (err , IsNil )
293
354
c .Assert (output , DeepEquals , expected )
355
+
356
+ s .assertShallows (c , r , 1 )
294
357
}
295
358
296
359
func (s * RemoteSuite ) TestFetchWithHashesAndReferences (c * C ) {
@@ -334,27 +397,28 @@ func (s *RemoteSuite) TestFetchWithHashesButMissing(c *C) {
334
397
})
335
398
336
399
c .Assert (err .Error (), Equals , "empty packfile" )
400
+ s .assertShallows (c , r , 0 )
401
+ }
402
+
403
+ func (s * RemoteSuite ) assertShallows (c * C , r * Remote , expected int ) {
404
+ shallowCommits , err := r .s .Shallow ()
405
+ c .Assert (err , IsNil )
406
+
407
+ c .Assert (shallowCommits , HasLen , expected )
337
408
}
338
409
339
410
func (s * RemoteSuite ) testFetch (c * C , r * Remote , o * FetchOptions , expected []* plumbing.Reference ) {
340
411
err := r .Fetch (o )
341
- c .Assert (err , IsNil )
412
+ if err != NoErrAlreadyUpToDate {
413
+ c .Assert (err , IsNil )
414
+ }
342
415
343
416
var refs int
344
417
l , err := r .s .IterReferences ()
345
418
c .Assert (err , IsNil )
346
419
l .ForEach (func (r * plumbing.Reference ) error { refs ++ ; return nil })
347
420
348
- if o .Depth > 0 {
349
- shallowCommits , err := r .s .Shallow ()
350
- c .Assert (err , IsNil )
351
-
352
- // Only the depth-most parent of any given commit will be shallow.
353
- commits := len (r .s .(* memory.Storage ).Commits ) / o .Depth
354
- c .Assert (shallowCommits , HasLen , commits )
355
- } else {
356
- c .Assert (refs , Equals , len (expected ))
357
- }
421
+ c .Assert (refs , Equals , len (expected ))
358
422
359
423
for _ , exp := range expected {
360
424
r , err := r .s .Reference (exp .Name ())
0 commit comments