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

Method TestDefaultRemote

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

Source from the content-addressed store, hash-verified

398}
399
400func (s *SubmoduleSuite) TestDefaultRemote(c *C) {
401 type testCase struct {
402 name string
403 remotes map[string]string // remote name → URL
404 branches map[string]string // branch name → branch.<name>.remote value
405 head *plumbing.Reference
406 want string // expected remote name
407 wantErrIn string // substring required in error message; "" means no error
408 }
409
410 hashRef := plumbing.NewHashReference(plumbing.HEAD, plumbing.NewHash("0000000000000000000000000000000000000001"))
411 mainSym := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.NewBranchReferenceName("main"))
412 tagSym := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/tags/v1"))
413
414 cases := []testCase{
415 {
416 name: "branch-override-wins",
417 remotes: map[string]string{"origin": "file:///o", "upstream": "file:///u"},
418 branches: map[string]string{"main": "upstream"},
419 head: mainSym,
420 want: "upstream",
421 },
422 {
423 name: "branch-override-with-bogus-remote",
424 remotes: map[string]string{"origin": "file:///o", "upstream": "file:///u"},
425 branches: map[string]string{"main": "bogus"},
426 head: mainSym,
427 wantErrIn: `remote "bogus" not found`,
428 },
429 {
430 name: "single-remote-wins-over-origin-fallback",
431 remotes: map[string]string{"upstream": "file:///u"},
432 head: hashRef,
433 want: "upstream",
434 },
435 {
436 name: "single-remote-with-empty-branch-remote",
437 remotes: map[string]string{"upstream": "file:///u"},
438 branches: map[string]string{"main": ""},
439 head: mainSym,
440 want: "upstream",
441 },
442 {
443 name: "origin-fallback-among-multiple",
444 remotes: map[string]string{"origin": "file:///o", "upstream": "file:///u"},
445 head: hashRef,
446 want: "origin",
447 },
448 {
449 name: "origin-fallback-not-present",
450 remotes: map[string]string{"upstream": "file:///u", "fork": "file:///f"},
451 head: hashRef,
452 wantErrIn: `remote "origin" not found`,
453 },
454 {
455 name: "no-remotes",
456 wantErrIn: `remote "origin" not found`,
457 },

Callers

nothing calls this directly

Calls 10

ConfigMethod · 0.95
NewHashReferenceFunction · 0.92
NewHashFunction · 0.92
NewSymbolicReferenceFunction · 0.92
NewBranchReferenceNameFunction · 0.92
ReferenceNameTypeAlias · 0.92
NewStorageFunction · 0.92
defaultRemoteFunction · 0.85
SetConfigMethod · 0.65
SetReferenceMethod · 0.65

Tested by

no test coverage detected