Refs returns all of the local and remote branches and tags for the current repository. Other refs (HEAD, refs/stash, git notes) are ignored.
()
| 505 | // Refs returns all of the local and remote branches and tags for the current |
| 506 | // repository. Other refs (HEAD, refs/stash, git notes) are ignored. |
| 507 | func LocalRefs() ([]*Ref, error) { |
| 508 | cmd, err := gitNoLFS("show-ref") |
| 509 | if err != nil { |
| 510 | return nil, errors.New(tr.Tr.Get("failed to find `git show-ref`: %v", err)) |
| 511 | } |
| 512 | |
| 513 | outp, err := cmd.StdoutPipe() |
| 514 | if err != nil { |
| 515 | return nil, errors.New(tr.Tr.Get("failed to call `git show-ref`: %v", err)) |
| 516 | } |
| 517 | |
| 518 | var refs []*Ref |
| 519 | |
| 520 | if err := cmd.Start(); err != nil { |
| 521 | return refs, err |
| 522 | } |
| 523 | |
| 524 | scanner := bufio.NewScanner(outp) |
| 525 | for scanner.Scan() { |
| 526 | line := strings.TrimSpace(scanner.Text()) |
| 527 | parts := strings.SplitN(line, " ", 2) |
| 528 | if len(parts) != 2 || !HasValidObjectIDLength(parts[0]) || len(parts[1]) < 1 { |
| 529 | tracerx.Printf("Invalid line from `git show-ref`: %q", line) |
| 530 | continue |
| 531 | } |
| 532 | |
| 533 | rtype, name := ParseRefToTypeAndName(parts[1]) |
| 534 | if rtype != RefTypeLocalBranch && rtype != RefTypeLocalTag { |
| 535 | continue |
| 536 | } |
| 537 | |
| 538 | refs = append(refs, &Ref{name, rtype, parts[0]}) |
| 539 | } |
| 540 | |
| 541 | return refs, cmd.Wait() |
| 542 | } |
| 543 | |
| 544 | // UpdateRef moves the given ref to a new sha with a given reason (and creates a |
| 545 | // reflog entry, if a "reason" was provided). It returns an error if any were |