MCPcopy Create free account
hub / github.com/celer-pkg/celer / GetDefaultBranch

Function GetDefaultBranch

pkgs/git/local.go:160–180  ·  view source on GitHub ↗

GetDefaultBranch read git default branch.

(nameVersion, repoDir string)

Source from the content-addressed store, hash-verified

158
159// GetDefaultBranch read git default branch.
160func GetDefaultBranch(nameVersion, repoDir string) (string, error) {
161 title := fmt.Sprintf("[read default branch: %s]", nameVersion)
162 executor := cmd.NewExecutor(title, "git", "remote", "show", "origin")
163 executor.SetWorkDir(repoDir)
164 output, err := executor.ExecuteOutput()
165 if err != nil {
166 return "", fmt.Errorf("read git default branch: %w", err)
167 }
168
169 lines := strings.SplitSeq(string(output), "\n")
170 for line := range lines {
171 if strings.Contains(line, "HEAD branch") {
172 parts := strings.Split(line, ":")
173 if len(parts) > 1 {
174 return strings.TrimSpace(parts[1]), nil
175 }
176 }
177 }
178
179 return "", fmt.Errorf("default branch not found of %s", repoDir)
180}
181
182// shortHash returns a concise git hash format: first 7 chars...last 7 chars
183func shortHash(hash string) string {

Callers 1

UpdateRepoFunction · 0.85

Calls 4

NewExecutorFunction · 0.92
SprintfMethod · 0.80
SetWorkDirMethod · 0.80
ExecuteOutputMethod · 0.80

Tested by

no test coverage detected