MCPcopy Create free account
hub / github.com/go-git/go-git / TestBrokenMultipleShallowFetch

Method TestBrokenMultipleShallowFetch

repository_test.go:3335–3396  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

3333}
3334
3335func (s *RepositorySuite) TestBrokenMultipleShallowFetch(c *C) {
3336 r, _ := Init(memory.NewStorage(), nil)
3337 _, err := r.CreateRemote(&config.RemoteConfig{
3338 Name: DefaultRemoteName,
3339 URLs: []string{s.GetBasicLocalRepositoryURL()},
3340 })
3341 c.Assert(err, IsNil)
3342
3343 c.Assert(r.Fetch(&FetchOptions{
3344 Depth: 2,
3345 RefSpecs: []config.RefSpec{config.RefSpec("refs/heads/master:refs/heads/master")},
3346 }), IsNil)
3347
3348 shallows, err := r.Storer.Shallow()
3349 c.Assert(err, IsNil)
3350 c.Assert(len(shallows), Equals, 1)
3351
3352 ref, err := r.Reference("refs/heads/master", true)
3353 c.Assert(err, IsNil)
3354 cobj, err := r.CommitObject(ref.Hash())
3355 c.Assert(err, IsNil)
3356 c.Assert(cobj, NotNil)
3357 err = object.NewCommitPreorderIter(cobj, nil, nil).ForEach(func(c *object.Commit) error {
3358 for _, ph := range c.ParentHashes {
3359 for _, h := range shallows {
3360 if ph == h {
3361 return storer.ErrStop
3362 }
3363 }
3364 }
3365
3366 return nil
3367 })
3368 c.Assert(err, IsNil)
3369
3370 c.Assert(r.Fetch(&FetchOptions{
3371 Depth: 5,
3372 RefSpecs: []config.RefSpec{config.RefSpec("refs/heads/*:refs/heads/*")},
3373 }), IsNil)
3374
3375 shallows, err = r.Storer.Shallow()
3376 c.Assert(err, IsNil)
3377 c.Assert(len(shallows), Equals, 3)
3378
3379 ref, err = r.Reference("refs/heads/master", true)
3380 c.Assert(err, IsNil)
3381 cobj, err = r.CommitObject(ref.Hash())
3382 c.Assert(err, IsNil)
3383 c.Assert(cobj, NotNil)
3384 err = object.NewCommitPreorderIter(cobj, nil, nil).ForEach(func(c *object.Commit) error {
3385 for _, ph := range c.ParentHashes {
3386 for _, h := range shallows {
3387 if ph == h {
3388 return storer.ErrStop
3389 }
3390 }
3391 }
3392

Callers

nothing calls this directly

Calls 12

NewStorageFunction · 0.92
RefSpecTypeAlias · 0.92
NewCommitPreorderIterFunction · 0.92
InitFunction · 0.85
CreateRemoteMethod · 0.80
CommitObjectMethod · 0.80
ShallowMethod · 0.65
ReferenceMethod · 0.65
HashMethod · 0.65
ForEachMethod · 0.65
FetchMethod · 0.45

Tested by

no test coverage detected