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

Method TestPushRequireRemoteRefs

remote_test.go:1394–1445  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

1392}
1393
1394func (s *RemoteSuite) TestPushRequireRemoteRefs(c *C) {
1395 f := fixtures.Basic().One()
1396 sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
1397
1398 dstFs := f.DotGit()
1399 dstSto := filesystem.NewStorage(dstFs, cache.NewObjectLRUDefault())
1400
1401 url := dstFs.Root()
1402 r := NewRemote(sto, &config.RemoteConfig{
1403 Name: DefaultRemoteName,
1404 URLs: []string{url},
1405 })
1406
1407 oldRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch"))
1408 c.Assert(err, IsNil)
1409 c.Assert(oldRef, NotNil)
1410
1411 otherRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/master"))
1412 c.Assert(err, IsNil)
1413 c.Assert(otherRef, NotNil)
1414
1415 err = r.Push(&PushOptions{
1416 RefSpecs: []config.RefSpec{"refs/heads/master:refs/heads/branch"},
1417 RequireRemoteRefs: []config.RefSpec{config.RefSpec(otherRef.Hash().String() + ":refs/heads/branch")},
1418 })
1419 c.Assert(err, ErrorMatches, "remote ref refs/heads/branch required to be .* but is .*")
1420
1421 newRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch"))
1422 c.Assert(err, IsNil)
1423 c.Assert(newRef, DeepEquals, oldRef)
1424
1425 err = r.Push(&PushOptions{
1426 RefSpecs: []config.RefSpec{"refs/heads/master:refs/heads/branch"},
1427 RequireRemoteRefs: []config.RefSpec{config.RefSpec(oldRef.Hash().String() + ":refs/heads/branch")},
1428 })
1429 c.Assert(err, ErrorMatches, "non-fast-forward update: .*")
1430
1431 newRef, err = dstSto.Reference(plumbing.ReferenceName("refs/heads/branch"))
1432 c.Assert(err, IsNil)
1433 c.Assert(newRef, DeepEquals, oldRef)
1434
1435 err = r.Push(&PushOptions{
1436 RefSpecs: []config.RefSpec{"refs/heads/master:refs/heads/branch"},
1437 RequireRemoteRefs: []config.RefSpec{config.RefSpec(oldRef.Hash().String() + ":refs/heads/branch")},
1438 Force: true,
1439 })
1440 c.Assert(err, IsNil)
1441
1442 newRef, err = dstSto.Reference(plumbing.ReferenceName("refs/heads/branch"))
1443 c.Assert(err, IsNil)
1444 c.Assert(newRef, Not(DeepEquals), oldRef)
1445}
1446
1447func (s *RemoteSuite) TestFetchPrune(c *C) {
1448 fs := fixtures.Basic().One().DotGit()

Callers

nothing calls this directly

Calls 10

PushMethod · 0.95
NewStorageFunction · 0.92
NewObjectLRUDefaultFunction · 0.92
ReferenceNameTypeAlias · 0.92
RefSpecTypeAlias · 0.92
NewRemoteFunction · 0.85
RootMethod · 0.80
ReferenceMethod · 0.65
StringMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected