MCPcopy
hub / github.com/cli/cli / CurrentBranch

Method CurrentBranch

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

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