mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 19:44:41 +00:00
37 lines
686 B
Go
37 lines
686 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
git "github.com/libgit2/git2go/v30"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type BranchStatus struct {
|
|
Name string
|
|
IsRemote bool
|
|
HasUpstream bool
|
|
NeedsPull bool
|
|
NeedsPush bool
|
|
}
|
|
|
|
func Branches(repo *git.Repository) ([]*git.Branch, error) {
|
|
it, err := repo.NewBranchIterator(git.BranchAll)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "Failed creating branch iterator")
|
|
}
|
|
|
|
it.ForEach(func(branch *git.Branch, branchType git.BranchType) error {
|
|
fmt.Print(branch.IsRemote())
|
|
upstream, err := branch.Upstream()
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
} else {
|
|
fmt.Println(upstream.Name())
|
|
}
|
|
return nil
|
|
})
|
|
|
|
return nil, nil
|
|
}
|