aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/close.go2
-rw-r--r--commands/comment.go2
-rw-r--r--commands/label.go2
-rw-r--r--commands/ls.go22
-rw-r--r--commands/open.go2
-rw-r--r--commands/pull.go55
-rw-r--r--commands/push.go3
-rw-r--r--commands/show.go2
-rw-r--r--commands/webui.go2
9 files changed, 22 insertions, 70 deletions
diff --git a/commands/close.go b/commands/close.go
index be0ff6e4..58446d71 100644
--- a/commands/close.go
+++ b/commands/close.go
@@ -18,7 +18,7 @@ func runCloseBug(cmd *cobra.Command, args []string) error {
prefix := args[0]
- b, err := bug.FindBug(repo, prefix)
+ b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
}
diff --git a/commands/comment.go b/commands/comment.go
index cbd34ab3..252fb7e4 100644
--- a/commands/comment.go
+++ b/commands/comment.go
@@ -44,7 +44,7 @@ func runComment(cmd *cobra.Command, args []string) error {
return err
}
- b, err := bug.FindBug(repo, prefix)
+ b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
}
diff --git a/commands/label.go b/commands/label.go
index 08d7a78a..e1679972 100644
--- a/commands/label.go
+++ b/commands/label.go
@@ -21,7 +21,7 @@ func runLabel(cmd *cobra.Command, args []string) error {
prefix := args[0]
- b, err := bug.FindBug(repo, prefix)
+ b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
}
diff --git a/commands/ls.go b/commands/ls.go
index 1bc2afff..5a5d96c6 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -2,28 +2,22 @@ package commands
import (
"fmt"
- b "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/util"
"github.com/spf13/cobra"
)
func runLsBug(cmd *cobra.Command, args []string) error {
- ids, err := repo.ListRefs(b.BugsRefPattern)
+ bugs := bug.ReadAllLocalBugs(repo)
- if err != nil {
- return err
- }
-
- for _, ref := range ids {
- bug, err := b.ReadBug(repo, b.BugsRefPattern+ref)
-
- if err != nil {
- return err
+ for b := range bugs {
+ if b.Err != nil {
+ return b.Err
}
- snapshot := bug.Compile()
+ snapshot := b.Bug.Compile()
- var author b.Person
+ var author bug.Person
if len(snapshot.Comments) > 0 {
create := snapshot.Comments[0]
@@ -35,7 +29,7 @@ func runLsBug(cmd *cobra.Command, args []string) error {
authorFmt := fmt.Sprintf("%-15.15s", author.Name)
fmt.Printf("%s %s\t%s\t%s\t%s\n",
- util.Cyan(bug.HumanId()),
+ util.Cyan(b.Bug.HumanId()),
util.Yellow(snapshot.Status),
titleFmt,
util.Magenta(authorFmt),
diff --git a/commands/open.go b/commands/open.go
index 6fe1e9d3..7fa59b49 100644
--- a/commands/open.go
+++ b/commands/open.go
@@ -18,7 +18,7 @@ func runOpenBug(cmd *cobra.Command, args []string) error {
prefix := args[0]
- b, err := bug.FindBug(repo, prefix)
+ b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
}
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)
}
}
diff --git a/commands/push.go b/commands/push.go
index 37479bfd..e2c29c68 100644
--- a/commands/push.go
+++ b/commands/push.go
@@ -16,9 +16,10 @@ func runPush(cmd *cobra.Command, args []string) error {
remote = args[0]
}
- if err := repo.PushRefs(remote, bug.BugsRefPattern+"*"); err != nil {
+ if err := bug.Push(repo, remote); err != nil {
return err
}
+
return nil
}
diff --git a/commands/show.go b/commands/show.go
index 9d330aab..8cf3e34a 100644
--- a/commands/show.go
+++ b/commands/show.go
@@ -20,7 +20,7 @@ func runShowBug(cmd *cobra.Command, args []string) error {
prefix := args[0]
- b, err := bug.FindBug(repo, prefix)
+ b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
}
diff --git a/commands/webui.go b/commands/webui.go
index c4db2ae6..802fc5df 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -19,7 +19,7 @@ func runWebUI(cmd *cobra.Command, args []string) error {
var err error
port, err = freeport.GetFreePort()
if err != nil {
- log.Fatal(err)
+ return err
}
}