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

Method ShowRefs

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

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

Callers 2

TestClientShowRefsFunction · 0.95
NewCreateContextFunction · 0.80

Calls 3

CommandMethod · 0.95
outputLinesFunction · 0.85
OutputMethod · 0.65

Tested by 1

TestClientShowRefsFunction · 0.76