MCPcopy
hub / github.com/cli/cli / ShowRefs

Method ShowRefs

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

241
242// ShowRefs resolves fully-qualified refs to commit hashes.
243func (c *Client) ShowRefs(ctx context.Context, refs []string) ([]Ref, error) {
244 args := append([]string{"show-ref", "--verify", "--"}, refs...)
245 cmd, err := c.Command(ctx, args...)
246 if err != nil {
247 return nil, err
248 }
249 // This functionality relies on parsing output from the git command despite
250 // an error status being returned from git.
251 out, err := cmd.Output()
252 var verified []Ref
253 for _, line := range outputLines(out) {
254 parts := strings.SplitN(line, " ", 2)
255 if len(parts) < 2 {
256 continue
257 }
258 verified = append(verified, Ref{
259 Hash: parts[0],
260 Name: parts[1],
261 })
262 }
263 return verified, err
264}
265
266func (c *Client) Config(ctx context.Context, name string) (string, error) {
267 args := []string{"config", name}

Callers 3

TestClientShowRefsFunction · 0.95
localBranchExistsFunction · 0.80
NewCreateContextFunction · 0.80

Calls 3

CommandMethod · 0.95
outputLinesFunction · 0.85
OutputMethod · 0.65

Tested by 1

TestClientShowRefsFunction · 0.76