6
0
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:
Grzegorz Dlugoszewski
2020-05-18 17:35:32 +02:00
parent 13f69bb4b5
commit 4ce4381c57
3 changed files with 59 additions and 5 deletions

36
branch.go Normal file
View 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
}