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

Method TestCheckoutRelativePathSubmoduleInitialized

worktree_test.go:622–677  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

620}
621
622func (s *WorktreeSuite) TestCheckoutRelativePathSubmoduleInitialized(c *C) {
623 url := "https://github.com/git-fixtures/submodule.git"
624 r := s.NewRepository(fixtures.ByURL(url).One())
625
626 // modify the .gitmodules from original one
627 file, err := r.wt.OpenFile(".gitmodules", os.O_WRONLY|os.O_TRUNC, 0666)
628 c.Assert(err, IsNil)
629
630 n, err := io.WriteString(file, `[submodule "basic"]
631 path = basic
632 url = ../basic.git
633[submodule "itself"]
634 path = itself
635 url = ../submodule.git`)
636 c.Assert(err, IsNil)
637 c.Assert(n, Not(Equals), 0)
638
639 w, err := r.Worktree()
640 c.Assert(err, IsNil)
641
642 w.Add(".gitmodules")
643 w.Commit("test", &CommitOptions{})
644
645 // test submodule path
646 modules, err := w.readGitmodulesFile()
647 c.Assert(err, IsNil)
648
649 c.Assert(modules.Submodules["basic"].URL, Equals, "../basic.git")
650 c.Assert(modules.Submodules["itself"].URL, Equals, "../submodule.git")
651
652 basicSubmodule, err := w.Submodule("basic")
653 c.Assert(err, IsNil)
654 basicRepo, err := basicSubmodule.Repository()
655 c.Assert(err, IsNil)
656 basicRemotes, err := basicRepo.Remotes()
657 c.Assert(err, IsNil)
658 c.Assert(basicRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/basic.git")
659
660 itselfSubmodule, err := w.Submodule("itself")
661 c.Assert(err, IsNil)
662 itselfRepo, err := itselfSubmodule.Repository()
663 c.Assert(err, IsNil)
664 itselfRemotes, err := itselfRepo.Remotes()
665 c.Assert(err, IsNil)
666 c.Assert(itselfRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/submodule.git")
667
668 sub, err := w.Submodules()
669 c.Assert(err, IsNil)
670
671 err = sub.Update(&SubmoduleUpdateOptions{Init: true, RecurseSubmodules: DefaultSubmoduleRecursionDepth})
672 c.Assert(err, IsNil)
673
674 status, err := w.Status()
675 c.Assert(err, IsNil)
676 c.Assert(status.IsClean(), Equals, true)
677}
678
679func (s *WorktreeSuite) TestCheckoutIndexMem(c *C) {

Callers

nothing calls this directly

Calls 14

WorktreeMethod · 0.95
NewRepositoryMethod · 0.80
OpenFileMethod · 0.80
readGitmodulesFileMethod · 0.80
SubmoduleMethod · 0.80
RepositoryMethod · 0.80
RemotesMethod · 0.80
SubmodulesMethod · 0.80
CommitMethod · 0.65
ConfigMethod · 0.65
AddMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected