@@ -14,7 +14,6 @@ import (
14
14
"github.com/go-git/go-git/v5/config"
15
15
"github.com/go-git/go-git/v5/plumbing"
16
16
"github.com/go-git/go-git/v5/plumbing/cache"
17
- "github.com/go-git/go-git/v5/plumbing/object"
18
17
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
19
18
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
20
19
"github.com/go-git/go-git/v5/plumbing/storer"
@@ -1175,7 +1174,7 @@ func (s *RemoteSuite) TestGetHaves(c *C) {
1175
1174
),
1176
1175
}
1177
1176
1178
- l , err := getHaves (localRefs , memory .NewStorage (), sto )
1177
+ l , err := getHaves (localRefs , memory .NewStorage (), sto , 0 )
1179
1178
c .Assert (err , IsNil )
1180
1179
c .Assert (l , HasLen , 2 )
1181
1180
}
@@ -1404,45 +1403,7 @@ func (s *RemoteSuite) TestCanPushShasToReference(c *C) {
1404
1403
c .Assert (err , IsNil )
1405
1404
c .Assert (repo , NotNil )
1406
1405
1407
- fd , err := os .Create (filepath .Join (d , "repo" , "README.md" ))
1408
- c .Assert (err , IsNil )
1409
- if err != nil {
1410
- return
1411
- }
1412
- _ , err = fd .WriteString ("# test repo" )
1413
- c .Assert (err , IsNil )
1414
- if err != nil {
1415
- return
1416
- }
1417
- err = fd .Close ()
1418
- c .Assert (err , IsNil )
1419
- if err != nil {
1420
- return
1421
- }
1422
-
1423
- wt , err := repo .Worktree ()
1424
- c .Assert (err , IsNil )
1425
- if err != nil {
1426
- return
1427
- }
1428
-
1429
- wt .Add ("README.md" )
1430
- sha , err := wt .Commit ("test commit" , & CommitOptions {
1431
- Author : & object.Signature {
1432
- Name : "test" ,
1433
- Email : "test@example.com" ,
1434
- When : time .Now (),
1435
- },
1436
- Committer : & object.Signature {
1437
- Name : "test" ,
1438
- Email : "test@example.com" ,
1439
- When : time .Now (),
1440
- },
1441
- })
1442
- c .Assert (err , IsNil )
1443
- if err != nil {
1444
- return
1445
- }
1406
+ sha := CommitNewFile (c , repo , "README.md" )
1446
1407
1447
1408
gitremote , err := repo .CreateRemote (& config.RemoteConfig {
1448
1409
Name : "local" ,
@@ -1472,3 +1433,69 @@ func (s *RemoteSuite) TestCanPushShasToReference(c *C) {
1472
1433
}
1473
1434
c .Assert (ref .Hash ().String (), Equals , sha .String ())
1474
1435
}
1436
+
1437
+ func (s * RemoteSuite ) TestFetchAfterShallowClone (c * C ) {
1438
+ tempDir , clean := s .TemporalDir ()
1439
+ defer clean ()
1440
+ remoteUrl := filepath .Join (tempDir , "remote" )
1441
+ repoDir := filepath .Join (tempDir , "repo" )
1442
+
1443
+ // Create a new repo and add more than 1 commit (so we can have a shallow commit)
1444
+ remote , err := PlainInit (remoteUrl , false )
1445
+ c .Assert (err , IsNil )
1446
+ c .Assert (remote , NotNil )
1447
+
1448
+ _ = CommitNewFile (c , remote , "File1" )
1449
+ _ = CommitNewFile (c , remote , "File2" )
1450
+
1451
+ // Clone the repo with a depth of 1
1452
+ repo , err := PlainClone (repoDir , false , & CloneOptions {
1453
+ URL : remoteUrl ,
1454
+ Depth : 1 ,
1455
+ Tags : NoTags ,
1456
+ SingleBranch : true ,
1457
+ ReferenceName : "master" ,
1458
+ })
1459
+ c .Assert (err , IsNil )
1460
+
1461
+ // Add new commits to the origin (more than 1 so that our next test hits a missing commit)
1462
+ _ = CommitNewFile (c , remote , "File3" )
1463
+ sha4 := CommitNewFile (c , remote , "File4" )
1464
+
1465
+ // Try fetch with depth of 1 again (note, we need to ensure no remote branch remains pointing at the old commit)
1466
+ r , err := repo .Remote (DefaultRemoteName )
1467
+ c .Assert (err , IsNil )
1468
+ s .testFetch (c , r , & FetchOptions {
1469
+ Depth : 2 ,
1470
+ Tags : NoTags ,
1471
+
1472
+ RefSpecs : []config.RefSpec {
1473
+ "+refs/heads/master:refs/heads/master" ,
1474
+ "+refs/heads/master:refs/remotes/origin/master" ,
1475
+ },
1476
+ }, []* plumbing.Reference {
1477
+ plumbing .NewReferenceFromStrings ("refs/heads/master" , sha4 .String ()),
1478
+ plumbing .NewReferenceFromStrings ("refs/remotes/origin/master" , sha4 .String ()),
1479
+ plumbing .NewSymbolicReference ("HEAD" , "refs/heads/master" ),
1480
+ })
1481
+
1482
+ // Add another commit to the origin
1483
+ sha5 := CommitNewFile (c , remote , "File5" )
1484
+
1485
+ // Try fetch with depth of 2 this time (to reach a commit that we don't have locally)
1486
+ r , err = repo .Remote (DefaultRemoteName )
1487
+ c .Assert (err , IsNil )
1488
+ s .testFetch (c , r , & FetchOptions {
1489
+ Depth : 1 ,
1490
+ Tags : NoTags ,
1491
+
1492
+ RefSpecs : []config.RefSpec {
1493
+ "+refs/heads/master:refs/heads/master" ,
1494
+ "+refs/heads/master:refs/remotes/origin/master" ,
1495
+ },
1496
+ }, []* plumbing.Reference {
1497
+ plumbing .NewReferenceFromStrings ("refs/heads/master" , sha5 .String ()),
1498
+ plumbing .NewReferenceFromStrings ("refs/remotes/origin/master" , sha5 .String ()),
1499
+ plumbing .NewSymbolicReference ("HEAD" , "refs/heads/master" ),
1500
+ })
1501
+ }
0 commit comments