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

Function TestCreateAndSwitchBranch

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

Source from the content-addressed store, hash-verified

80}
81
82func TestCreateAndSwitchBranch(t *testing.T) {
83 tmpDir := testutil.TempDir(t, "test-*")
84
85 originalDir, err := os.Getwd()
86 require.NoError(t, err, "get current directory for test setup")
87 defer func() {
88 _ = os.Chdir(originalDir)
89 }()
90
91 require.NoError(t, os.Chdir(tmpDir), "change to temp directory for test setup")
92
93 // Initialize git repo
94 if err := exec.Command("git", "init").Run(); err != nil {
95 t.Skip("Git not available")
96 }
97
98 // Configure git
99 exec.Command("git", "config", "user.name", "Test User").Run()
100 exec.Command("git", "config", "user.email", "test@example.com").Run()
101
102 // Create initial commit
103 require.NoError(t, os.WriteFile("test.txt", []byte("test"), 0644), "create initial test file")
104 exec.Command("git", "add", "test.txt").Run()
105 if err := exec.Command("git", "commit", "-m", "Initial commit").Run(); err != nil {
106 t.Skip("Failed to create initial commit")
107 }
108
109 // Create and switch to new branch
110 branchName := "test-branch"
111 err = createAndSwitchBranch(branchName, false)
112 require.NoError(t, err, "create and switch to new branch")
113
114 // Verify we're on the new branch
115 currentBranch, err := getCurrentBranch()
116 require.NoError(t, err, "get current branch after branch switch")
117 assert.Equal(t, branchName, currentBranch, "current branch should match the newly created branch")
118}
119
120func TestSwitchBranch(t *testing.T) {
121 tmpDir := testutil.TempDir(t, "test-*")

Callers

nothing calls this directly

Calls 4

TempDirFunction · 0.92
createAndSwitchBranchFunction · 0.85
getCurrentBranchFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected