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

Function getCurrentBranch

pkg/cli/git.go:445–462  ·  view source on GitHub ↗

getCurrentBranch gets the current git branch name

()

Source from the content-addressed store, hash-verified

443
444// getCurrentBranch gets the current git branch name
445func getCurrentBranch() (string, error) {
446 gitLog.Print("Getting current git branch")
447 cmd := exec.Command("git", "branch", "--show-current")
448 output, err := cmd.Output()
449 if err != nil {
450 gitLog.Printf("Failed to get current branch: %v", err)
451 return "", fmt.Errorf("failed to get current branch: %w", err)
452 }
453
454 branch := strings.TrimSpace(string(output))
455 if branch == "" {
456 gitLog.Print("Could not determine current branch")
457 return "", errors.New("could not determine current branch")
458 }
459
460 gitLog.Printf("Current branch: %s", branch)
461 return branch, nil
462}
463
464// createAndSwitchBranch creates a new branch and switches to it
465func createAndSwitchBranch(branchName string, verbose bool) error {

Callers 10

TestGetCurrentBranchFunction · 0.70
TestSwitchBranchFunction · 0.70
applyPatchToRepoFunction · 0.70
updateLocalBranchMethod · 0.70
RunWorkflowOnGitHubFunction · 0.70
pushWorkflowFilesFunction · 0.70
CreatePRWithChangesFunction · 0.70
addWorkflowsWithPRFunction · 0.70

Calls 3

PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 4

TestGetCurrentBranchFunction · 0.56
TestSwitchBranchFunction · 0.56