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

Method CurrentBranch

git/client.go:216–234  ·  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

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

Callers

nothing calls this directly

Calls 3

CommandMethod · 0.95
firstLineFunction · 0.70
OutputMethod · 0.65

Tested by

no test coverage detected