MCPcopy
hub / github.com/go-git/go-git / TestCheckoutRelativePathSubmoduleInitialized

Method TestCheckoutRelativePathSubmoduleInitialized

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

Source from the content-addressed store, hash-verified

675}
676
677func (s *WorktreeSuite) TestCheckoutRelativePathSubmoduleInitialized(c *C) {
678 url := "https://github.com/git-fixtures/submodule.git"
679 r := s.NewRepository(fixtures.ByURL(url).One())
680
681 // modify the .gitmodules from original one
682 file, err := r.wt.OpenFile(".gitmodules", os.O_WRONLY|os.O_TRUNC, 0666)
683 c.Assert(err, IsNil)
684
685 n, err := io.WriteString(file, `[submodule "basic"]
686 path = basic
687 url = ../basic.git
688[submodule "itself"]
689 path = itself
690 url = ../submodule.git`)
691 c.Assert(err, IsNil)
692 c.Assert(n, Not(Equals), 0)
693
694 w, err := r.Worktree()
695 c.Assert(err, IsNil)
696
697 w.Add(".gitmodules")
698 w.Commit("test", &CommitOptions{})
699
700 // test submodule path
701 modules, err := w.readGitmodulesFile()
702 c.Assert(err, IsNil)
703
704 c.Assert(modules.Submodules["basic"].URL, Equals, "../basic.git")
705 c.Assert(modules.Submodules["itself"].URL, Equals, "../submodule.git")
706
707 basicSubmodule, err := w.Submodule("basic")
708 c.Assert(err, IsNil)
709 basicRepo, err := basicSubmodule.Repository()
710 c.Assert(err, IsNil)
711 basicRemotes, err := basicRepo.Remotes()
712 c.Assert(err, IsNil)
713 c.Assert(basicRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/basic.git")
714
715 itselfSubmodule, err := w.Submodule("itself")
716 c.Assert(err, IsNil)
717 itselfRepo, err := itselfSubmodule.Repository()
718 c.Assert(err, IsNil)
719 itselfRemotes, err := itselfRepo.Remotes()
720 c.Assert(err, IsNil)
721 c.Assert(itselfRemotes[0].Config().URLs[0], Equals, "https://github.com/git-fixtures/submodule.git")
722
723 sub, err := w.Submodules()
724 c.Assert(err, IsNil)
725
726 err = sub.Update(&SubmoduleUpdateOptions{Init: true, RecurseSubmodules: DefaultSubmoduleRecursionDepth})
727 c.Assert(err, IsNil)
728
729 status, err := w.Status()
730 c.Assert(err, IsNil)
731 c.Assert(status.IsClean(), Equals, true)
732}
733
734func (s *WorktreeSuite) TestCheckoutIndexMem(c *C) {

Callers

nothing calls this directly

Calls 14

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

Tested by

no test coverage detected