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

Method TestSubmoduleRelativeURLPicksOrigin

submodule_test.go:505–548  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

503}
504
505func (s *SubmoduleSuite) TestSubmoduleRelativeURLPicksOrigin(c *C) {
506 // Two remotes plus a relative submodule URL. With the prior code,
507 // remotes[0] from map iteration could be either origin or upstream;
508 // the resolved submodule URL therefore differed across runs. Loop
509 // 20× to exercise different map orderings within a single test run
510 // — every iteration must resolve against origin.
511 for i := range 20 {
512 parent := &Repository{
513 Storer: memory.NewStorage(),
514 wt: memfs.New(),
515 }
516 cfg, err := parent.Config()
517 c.Assert(err, IsNil)
518 cfg.Remotes["origin"] = &config.RemoteConfig{
519 Name: "origin",
520 URLs: []string{"file:///parent/origin"},
521 }
522 cfg.Remotes["upstream"] = &config.RemoteConfig{
523 Name: "upstream",
524 URLs: []string{"file:///parent/upstream"},
525 }
526 c.Assert(parent.Storer.SetConfig(cfg), IsNil)
527
528 sub := &Submodule{
529 initialized: true,
530 w: &Worktree{Filesystem: memfs.New(), r: parent},
531 c: &config.Submodule{
532 Name: "child",
533 Path: "child",
534 URL: "../child",
535 },
536 }
537
538 subRepo, err := sub.Repository()
539 c.Assert(err, IsNil, Commentf("iteration %d", i))
540
541 remotes, err := subRepo.Remotes()
542 c.Assert(err, IsNil)
543 c.Assert(remotes, HasLen, 1, Commentf("iteration %d", i))
544 c.Assert(remotes[0].Config().URLs[0], Equals,
545 "file:///parent/child",
546 Commentf("iteration %d: expected URL resolved against origin", i))
547 }
548}
549
550func (s *SubmoduleSuite) TestSubmoduleRelativeURLRemoteWithoutURLs(c *C) {
551 // Defense in depth: a relative submodule URL must be joined onto

Callers

nothing calls this directly

Calls 6

ConfigMethod · 0.95
RepositoryMethod · 0.95
NewStorageFunction · 0.92
RemotesMethod · 0.80
SetConfigMethod · 0.65
ConfigMethod · 0.65

Tested by

no test coverage detected