MCPcopy Index your code
hub / github.com/git-lfs/git-lfs / LocalRefs

Function LocalRefs

git/git.go:507–542  ·  view source on GitHub ↗

Refs returns all of the local and remote branches and tags for the current repository. Other refs (HEAD, refs/stash, git notes) are ignored.

()

Source from the content-addressed store, hash-verified

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.
507func 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

Callers 2

lfsPushRefsFunction · 0.92
TestLocalRefsFunction · 0.85

Calls 9

NewFunction · 0.92
gitNoLFSFunction · 0.85
HasValidObjectIDLengthFunction · 0.85
ParseRefToTypeAndNameFunction · 0.85
StdoutPipeMethod · 0.80
GetMethod · 0.65
ScanMethod · 0.65
WaitMethod · 0.65
StartMethod · 0.45

Tested by 1

TestLocalRefsFunction · 0.68