diff --git a/branch.go b/branch.go new file mode 100644 index 0000000..178513d --- /dev/null +++ b/branch.go @@ -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 +} diff --git a/branch_test.go b/branch_test.go new file mode 100644 index 0000000..58b483f --- /dev/null +++ b/branch_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "testing" + + git "github.com/libgit2/git2go/v30" +) + +func TestBranches(t *testing.T) { + repo, err := git.OpenRepository("/home/grdl/workspace/gitlab.com/grdl/git-get") + checkFatal(t, err) + + branches, err := Branches(repo) + checkFatal(t, err) + + fmt.Println(len(branches)) +} diff --git a/status.go b/status.go index 3801e6c..00a39e3 100644 --- a/status.go +++ b/status.go @@ -17,12 +17,12 @@ const ( func GetStatus(path string) ([]RepoStatus, error) { repo, err := git.OpenRepository(path) if err != nil { - return nil, errors.Wrap(err, "failed opening repository") + return nil, errors.Wrap(err, "Failed opening repository") } entries, err := statusEntries(repo) if err != nil { - return nil, errors.Wrap(err, "failed opening repository") + return nil, errors.Wrap(err, "Failed opening repository") } statusSet := make(map[RepoStatus]bool) @@ -59,19 +59,19 @@ func statusEntries(repo *git.Repository) ([]git.StatusEntry, error) { status, err := repo.StatusList(opts) if err != nil { - return nil, errors.Wrap(err, "failed getting repository status") + return nil, errors.Wrap(err, "Failed getting repository status") } entryCount, err := status.EntryCount() if err != nil { - return nil, errors.Wrap(err, "failed getting repository status count") + return nil, errors.Wrap(err, "Failed getting repository status count") } var entries []git.StatusEntry for i := 0; i < entryCount; i++ { entry, err := status.ByIndex(i) if err != nil { - return nil, errors.Wrap(err, "failed getting repository status entry") + return nil, errors.Wrap(err, "Failed getting repository status entry") } entries = append(entries, entry)