git-bug/bug/bug_actions.go

59 lines
1.8 KiB
Go
Raw Normal View History

package bug
import (
2021-01-25 14:39:34 +03:00
"github.com/pkg/errors"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
)
2019-02-03 21:55:35 +03:00
// Fetch retrieve updates from a remote
2018-09-02 16:37:28 +03:00
// This does not change the local bugs state
2018-08-12 22:09:30 +03:00
func Fetch(repo repository.Repo, remote string) (string, error) {
return dag.Fetch(def, repo, remote)
}
2018-09-02 16:37:28 +03:00
// Push update a remote with the local changes
2018-08-12 22:09:30 +03:00
func Push(repo repository.Repo, remote string) (string, error) {
return dag.Push(def, repo, remote)
}
// Pull will do a Fetch + MergeAll
// This function will return an error if a merge fail
func Pull(repo repository.ClockedRepo, remote string, author identity.Interface) error {
_, err := Fetch(repo, remote)
2018-08-12 22:09:30 +03:00
if err != nil {
return err
}
for merge := range MergeAll(repo, remote, author) {
if merge.Err != nil {
return merge.Err
}
if merge.Status == entity.MergeStatusInvalid {
return errors.Errorf("merge failure: %s", merge.Reason)
2018-11-21 20:56:12 +03:00
}
}
2018-08-12 22:09:30 +03:00
return nil
}
// MergeAll will merge all the available remote bug
// Note: an author is necessary for the case where a merge commit is created, as this commit will
// have an author and may be signed if a signing key is available.
func MergeAll(repo repository.ClockedRepo, remote string, author identity.Interface) <-chan entity.MergeResult {
// no caching for the merge, we load everything from git even if that means multiple
// copy of the same entity in memory. The cache layer will intercept the results to
// invalidate entities if necessary.
identityResolver := identity.NewSimpleResolver(repo)
return dag.MergeAll(def, repo, identityResolver, remote, author)
}
// RemoveBug will remove a local bug from its entity.Id
func RemoveBug(repo repository.ClockedRepo, id entity.Id) error {
return dag.Remove(def, repo, id)
}