1package bug
2
3import (
4 "github.com/pkg/errors"
5
6 "github.com/MichaelMure/git-bug/entity"
7 "github.com/MichaelMure/git-bug/entity/dag"
8 "github.com/MichaelMure/git-bug/identity"
9 "github.com/MichaelMure/git-bug/repository"
10)
11
12// Fetch retrieve updates from a remote
13// This does not change the local bugs state
14func Fetch(repo repository.Repo, remote string) (string, error) {
15 return dag.Fetch(def, repo, remote)
16}
17
18// Push update a remote with the local changes
19func Push(repo repository.Repo, remote string) (string, error) {
20 return dag.Push(def, repo, remote)
21}
22
23// Pull will do a Fetch + MergeAll
24// This function will return an error if a merge fail
25// Note: an author is necessary for the case where a merge commit is created, as this commit will
26// have an author and may be signed if a signing key is available.
27func Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) error {
28 _, err := Fetch(repo, remote)
29 if err != nil {
30 return err
31 }
32
33 for merge := range MergeAll(repo, resolvers, remote, mergeAuthor) {
34 if merge.Err != nil {
35 return merge.Err
36 }
37 if merge.Status == entity.MergeStatusInvalid {
38 return errors.Errorf("merge failure: %s", merge.Reason)
39 }
40 }
41
42 return nil
43}
44
45// MergeAll will merge all the available remote bug
46// Note: an author is necessary for the case where a merge commit is created, as this commit will
47// have an author and may be signed if a signing key is available.
48func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult {
49 out := make(chan entity.MergeResult)
50
51 go func() {
52 defer close(out)
53
54 results := dag.MergeAll(def, repo, resolvers, remote, mergeAuthor)
55
56 // wrap the dag.Entity into a complete Bug
57 for result := range results {
58 result := result
59 if result.Entity != nil {
60 result.Entity = &Bug{
61 Entity: result.Entity.(*dag.Entity),
62 }
63 }
64 out <- result
65 }
66 }()
67
68 return out
69}
70
71// RemoveBug will remove a local bug from its entity.Id
72func RemoveBug(repo repository.ClockedRepo, id entity.Id) error {
73 return dag.Remove(def, repo, id)
74}