aboutsummaryrefslogtreecommitdiffstats
path: root/commands/pull.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-23 00:04:46 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-23 00:04:46 +0200
commit17e2ec8f5679c1ba7ae2ea45290e9303beb3c227 (patch)
treec8862ebf6e9e9314361120127bf3fc59877c3e02 /commands/pull.go
parente1f597639bfc2f796f74afa87e41581087f0b26e (diff)
downloadgit-bug-17e2ec8f5679c1ba7ae2ea45290e9303beb3c227.tar.gz
bug: refactor to limit abstraction leak and to have a more reusable code for the UIs
Diffstat (limited to 'commands/pull.go')
-rw-r--r--commands/pull.go55
1 files changed, 6 insertions, 49 deletions
diff --git a/commands/pull.go b/commands/pull.go
index 83c2101a..ac6a3732 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -19,62 +19,19 @@ func runPull(cmd *cobra.Command, args []string) error {
fmt.Printf("Fetching remote ...\n\n")
- if err := repo.FetchRefs(remote, bug.BugsRefPattern+"*", bug.BugsRemoteRefPattern+"*"); err != nil {
+ if err := bug.Fetch(repo, remote); err != nil {
return err
}
fmt.Printf("\nMerging data ...\n\n")
- remoteRefSpec := fmt.Sprintf(bug.BugsRemoteRefPattern, remote)
- remoteRefs, err := repo.ListRefs(remoteRefSpec)
-
- if err != nil {
- return err
- }
-
- for _, ref := range remoteRefs {
- remoteRef := fmt.Sprintf(bug.BugsRemoteRefPattern, remote) + ref
- remoteBug, err := bug.ReadBug(repo, remoteRef)
-
- if err != nil {
- return err
- }
-
- // Check for error in remote data
- if !remoteBug.IsValid() {
- fmt.Printf("%s: %s\n", remoteBug.HumanId(), "invalid remote data")
- continue
- }
-
- localRef := bug.BugsRefPattern + remoteBug.Id()
- localExist, err := repo.RefExist(localRef)
-
- // the bug is not local yet, simply create the reference
- if !localExist {
- err := repo.CopyRef(remoteRef, localRef)
-
- if err != nil {
- return err
- }
-
- fmt.Printf("%s: %s\n", remoteBug.HumanId(), "new")
- continue
- }
-
- localBug, err := bug.ReadBug(repo, localRef)
-
- if err != nil {
- return err
- }
-
- updated, err := localBug.Merge(repo, remoteBug)
-
- if err != nil {
- return err
+ for merge := range bug.MergeAll(repo, remote) {
+ if merge.Err != nil {
+ return merge.Err
}
- if updated {
- fmt.Printf("%s: %s\n", remoteBug.HumanId(), "updated")
+ if merge.Status != bug.MsgNothing {
+ fmt.Printf("%s: %s\n", merge.HumanId, merge.Status)
}
}