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

Method ShowRefs

git/client.go:237–258  ·  view source on GitHub ↗

ShowRefs resolves fully-qualified refs to commit hashes.

(ctx context.Context, refs []string)

Source from the content-addressed store, hash-verified

235
236// ShowRefs resolves fully-qualified refs to commit hashes.
237func (c *Client) ShowRefs(ctx context.Context, refs []string) ([]Ref, error) {
238 args := append([]string{"show-ref", "--verify", "--"}, refs...)
239 cmd, err := c.Command(ctx, args...)
240 if err != nil {
241 return nil, err
242 }
243 // This functionality relies on parsing output from the git command despite
244 // an error status being returned from git.
245 out, err := cmd.Output()
246 var verified []Ref
247 for _, line := range outputLines(out) {
248 parts := strings.SplitN(line, " ", 2)
249 if len(parts) < 2 {
250 continue
251 }
252 verified = append(verified, Ref{
253 Hash: parts[0],
254 Name: parts[1],
255 })
256 }
257 return verified, err
258}
259
260// Worktrees lists the repository's worktrees by parsing the output of
261// `git worktree list --porcelain`.

Calls 3

CommandMethod · 0.95
outputLinesFunction · 0.85
OutputMethod · 0.65