MCPcopy Create free account
hub / github.com/cli/cli / CurrentBranch

Method CurrentBranch

git/client.go:223–241  ·  view source on GitHub ↗

CurrentBranch reads the checked-out branch for the git repository.

(ctx context.Context)

Source from the content-addressed store, hash-verified

221
222// CurrentBranch reads the checked-out branch for the git repository.
223func (c *Client) CurrentBranch(ctx context.Context) (string, error) {
224 args := []string{"symbolic-ref", "--quiet", "HEAD"}
225 cmd, err := c.Command(ctx, args...)
226 if err != nil {
227 return "", err
228 }
229 out, err := cmd.Output()
230 if err != nil {
231 var gitErr *GitError
232 if ok := errors.As(err, &gitErr); ok && len(gitErr.Stderr) == 0 {
233 gitErr.err = ErrNotOnAnyBranch
234 gitErr.Stderr = "not on any branch"
235 return "", gitErr
236 }
237 return "", err
238 }
239 branch := firstLine(out)
240 return strings.TrimPrefix(branch, "refs/heads/"), nil
241}
242
243// ShowRefs resolves fully-qualified refs to commit hashes.
244func (c *Client) ShowRefs(ctx context.Context, refs []string) ([]Ref, error) {

Callers 1

TestClientCurrentBranchFunction · 0.95

Calls 3

CommandMethod · 0.95
firstLineFunction · 0.85
OutputMethod · 0.65

Tested by 1

TestClientCurrentBranchFunction · 0.76