2018-07-23 01:04:46 +03:00
|
|
|
package bug
|
|
|
|
|
|
|
|
import (
|
2021-01-25 14:39:34 +03:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2019-03-27 23:44:11 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2021-02-14 13:36:32 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity/dag"
|
2020-09-16 17:22:02 +03:00
|
|
|
"github.com/MichaelMure/git-bug/identity"
|
2018-08-05 16:23:51 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-07-23 01:04:46 +03:00
|
|
|
)
|
|
|
|
|
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) {
|
2021-02-14 13:36:32 +03:00
|
|
|
return dag.Fetch(def, repo, remote)
|
2018-07-23 01:04:46 +03:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-02-14 13:36:32 +03:00
|
|
|
return dag.Push(def, repo, remote)
|
2018-07-23 01:04:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 18:10:40 +03:00
|
|
|
// Pull will do a Fetch + MergeAll
|
2019-02-16 15:48:46 +03:00
|
|
|
// This function will return an error if a merge fail
|
2021-02-14 13:36:32 +03:00
|
|
|
func Pull(repo repository.ClockedRepo, remote string, author identity.Interface) error {
|
2019-03-25 23:09:56 +03:00
|
|
|
_, err := Fetch(repo, remote)
|
2018-08-12 22:09:30 +03:00
|
|
|
if err != nil {
|
2018-07-25 19:01:32 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-14 13:36:32 +03:00
|
|
|
for merge := range MergeAll(repo, remote, author) {
|
2018-07-25 19:01:32 +03:00
|
|
|
if merge.Err != nil {
|
|
|
|
return merge.Err
|
|
|
|
}
|
2019-03-27 23:44:11 +03:00
|
|
|
if merge.Status == entity.MergeStatusInvalid {
|
2019-02-16 15:48:46 +03:00
|
|
|
return errors.Errorf("merge failure: %s", merge.Reason)
|
2018-11-21 20:56:12 +03:00
|
|
|
}
|
2018-07-25 19:01:32 +03:00
|
|
|
}
|
2018-08-12 22:09:30 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-14 13:36:32 +03:00
|
|
|
// 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 {
|
2020-09-16 17:22:02 +03:00
|
|
|
// 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)
|
|
|
|
|
2021-02-14 14:38:09 +03:00
|
|
|
out := make(chan entity.MergeResult)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(out)
|
|
|
|
|
|
|
|
results := dag.MergeAll(def, repo, identityResolver, remote, author)
|
|
|
|
|
|
|
|
// wrap the dag.Entity into a complete Bug
|
|
|
|
for result := range results {
|
|
|
|
result := result
|
|
|
|
if result.Entity != nil {
|
|
|
|
result.Entity = &Bug{
|
|
|
|
Entity: result.Entity.(*dag.Entity),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out <- result
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return out
|
2021-02-14 13:36:32 +03:00
|
|
|
}
|
2018-07-23 01:04:46 +03:00
|
|
|
|
2021-02-14 13:36:32 +03:00
|
|
|
// 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)
|
2018-07-23 01:04:46 +03:00
|
|
|
}
|