aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bug/bug_actions.go91
-rw-r--r--bug/operation.go2
-rw-r--r--cache/repo_cache.go2
-rw-r--r--commands/pull.go2
-rw-r--r--termui/bug_table.go2
5 files changed, 60 insertions, 39 deletions
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index a51a1bf9..8bda15b7 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -7,11 +7,6 @@ import (
"github.com/MichaelMure/git-bug/repository"
)
-const MsgMergeNew = "new"
-const MsgMergeInvalid = "invalid data"
-const MsgMergeUpdated = "updated"
-const MsgMergeNothing = "nothing to do"
-
// Fetch retrieve update from a remote
// This does not change the local bugs state
func Fetch(repo repository.Repo, remote string) (string, error) {
@@ -44,32 +39,6 @@ func Pull(repo repository.Repo, remote string) error {
return nil
}
-type MergeResult struct {
- // Err is set when a terminal error occur in the process
- Err error
-
- Id string
- Status string
- Bug *Bug
-}
-
-func newMergeError(err error, id string) MergeResult {
- return MergeResult{
- Err: err,
- Id: id,
- }
-}
-
-func newMergeStatus(status string, id string, bug *Bug) MergeResult {
- return MergeResult{
- Id: id,
- Status: status,
-
- // Bug is not set for an invalid merge result
- Bug: bug,
- }
-}
-
// MergeAll will merge all the available remote bug
func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
out := make(chan MergeResult)
@@ -98,7 +67,7 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
// Check for error in remote data
if !remoteBug.IsValid() {
- out <- newMergeStatus(MsgMergeInvalid, id, nil)
+ out <- newMergeStatus(MergeStatusInvalid, id, nil)
continue
}
@@ -119,7 +88,7 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
return
}
- out <- newMergeStatus(MsgMergeNew, id, remoteBug)
+ out <- newMergeStatus(MergeStatusNew, id, remoteBug)
continue
}
@@ -138,12 +107,64 @@ func MergeAll(repo repository.Repo, remote string) <-chan MergeResult {
}
if updated {
- out <- newMergeStatus(MsgMergeUpdated, id, localBug)
+ out <- newMergeStatus(MergeStatusUpdated, id, localBug)
} else {
- out <- newMergeStatus(MsgMergeNothing, id, localBug)
+ out <- newMergeStatus(MergeStatusNothing, id, localBug)
}
}
}()
return out
}
+
+// MergeStatus represent the result of a merge operation of a bug
+type MergeStatus int
+
+const (
+ _ MergeStatus = iota
+ MergeStatusNew
+ MergeStatusInvalid
+ MergeStatusUpdated
+ MergeStatusNothing
+)
+
+func (ms MergeStatus) String() string {
+ switch ms {
+ case MergeStatusNew:
+ return "new"
+ case MergeStatusInvalid:
+ return "invalid data"
+ case MergeStatusUpdated:
+ return "updated"
+ case MergeStatusNothing:
+ return "nothing to do"
+ default:
+ panic("unknown merge status")
+ }
+}
+
+type MergeResult struct {
+ // Err is set when a terminal error occur in the process
+ Err error
+
+ Id string
+ Status MergeStatus
+ Bug *Bug
+}
+
+func newMergeError(err error, id string) MergeResult {
+ return MergeResult{
+ Err: err,
+ Id: id,
+ }
+}
+
+func newMergeStatus(status MergeStatus, id string, bug *Bug) MergeResult {
+ return MergeResult{
+ Id: id,
+ Status: status,
+
+ // Bug is not set for an invalid merge result
+ Bug: bug,
+ }
+}
diff --git a/bug/operation.go b/bug/operation.go
index 5d42a175..6a8aa0cd 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -5,7 +5,7 @@ import (
"time"
)
-// OperationType is an identifier
+// OperationType is an operation type identifier
type OperationType int
const (
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index d8b14501..0d33494d 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -313,7 +313,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult {
id := result.Id
switch result.Status {
- case bug.MsgMergeNew, bug.MsgMergeUpdated:
+ case bug.MergeStatusNew, bug.MergeStatusUpdated:
b := result.Bug
snap := b.Compile()
c.excerpts[id] = NewBugExcerpt(b, &snap)
diff --git a/commands/pull.go b/commands/pull.go
index 9a5f4e5c..64de8bf5 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -41,7 +41,7 @@ func runPull(cmd *cobra.Command, args []string) error {
return merge.Err
}
- if merge.Status != bug.MsgMergeNothing {
+ if merge.Status != bug.MergeStatusNothing {
fmt.Printf("%s: %s\n", merge.Bug.HumanId(), merge.Status)
}
}
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 9ac04608..5bd5bf64 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -423,7 +423,7 @@ func (bt *bugTable) pull(g *gocui.Gui, v *gocui.View) error {
beginLine := ""
for merge := range bt.repo.MergeAll(defaultRemote) {
- if merge.Status == bug.MsgMergeNothing {
+ if merge.Status == bug.MergeStatusNothing {
continue
}