MCPcopy Create free account
hub / github.com/github/gh-aw / TestGetRepositorySlugFromRemoteFallback

Function TestGetRepositorySlugFromRemoteFallback

pkg/cli/git_test.go:656–691  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

654}
655
656func TestGetRepositorySlugFromRemoteFallback(t *testing.T) {
657 tmpDir := testutil.TempDir(t, "test-slug-fallback-*")
658
659 originalDir, err := os.Getwd()
660 require.NoError(t, err, "get current directory for test setup")
661 defer func() {
662 if err := os.Chdir(originalDir); err != nil {
663 t.Logf("Warning: failed to restore directory: %v", err)
664 }
665 }()
666
667 require.NoError(t, os.Chdir(tmpDir), "change to temp directory for test setup")
668
669 // Initialize a git repo
670 if err := exec.Command("git", "init").Run(); err != nil {
671 t.Skip("Git not available")
672 }
673
674 t.Run("single non-origin remote provides repo slug", func(t *testing.T) {
675 require.NoError(t, exec.Command("git", "remote", "add", "myorg", "https://github.com/myorg/myrepo.git").Run(), "add fallback remote")
676 defer func() { _ = exec.Command("git", "remote", "remove", "myorg").Run() }()
677
678 slug := getRepositorySlugFromRemote()
679 assert.Equal(t, "myorg/myrepo", slug, "getRepositorySlugFromRemote should return the only configured non-origin slug")
680 })
681
682 t.Run("multiple non-origin remotes returns empty slug", func(t *testing.T) {
683 require.NoError(t, exec.Command("git", "remote", "add", "remote1", "https://github.com/org1/repo1.git").Run(), "add first non-origin remote")
684 defer func() { _ = exec.Command("git", "remote", "remove", "remote1").Run() }()
685 require.NoError(t, exec.Command("git", "remote", "add", "remote2", "https://github.com/org2/repo2.git").Run(), "add second non-origin remote")
686 defer func() { _ = exec.Command("git", "remote", "remove", "remote2").Run() }()
687
688 slug := getRepositorySlugFromRemote()
689 assert.Empty(t, slug, "getRepositorySlugFromRemote should return an empty slug when multiple non-origin remotes exist")
690 })
691}

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected