mirror of
https://github.com/grdl/git-get.git
synced 2026-02-10 13:44:17 +00:00
Add a basic branch iterator for getting branches state
This commit is contained in:
36
branch.go
Normal file
36
branch.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user