aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/ls.go6
-rw-r--r--commands/new.go3
-rw-r--r--commands/pull.go61
3 files changed, 66 insertions, 4 deletions
diff --git a/commands/ls.go b/commands/ls.go
index dea2bba2..94755b2d 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -7,14 +7,14 @@ import (
)
func runLsBug(repo repository.Repo, args []string) error {
- refs, err := repo.ListRefs(b.BugsRefPattern)
+ ids, err := repo.ListRefs(b.BugsRefPattern)
if err != nil {
return err
}
- for _, ref := range refs {
- bug, err := b.ReadBug(repo, ref)
+ for _, ref := range ids {
+ bug, err := b.ReadBug(repo, b.BugsRefPattern+ref)
if err != nil {
return err
diff --git a/commands/new.go b/commands/new.go
index a2373515..4f6008cf 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -3,6 +3,7 @@ package commands
import (
"errors"
"flag"
+ "fmt"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/bug/operations"
"github.com/MichaelMure/git-bug/commands/input"
@@ -60,6 +61,8 @@ func runNewBug(repo repository.Repo, args []string) error {
err = newbug.Commit(repo)
+ fmt.Println(newbug.HumanId())
+
return err
}
diff --git a/commands/pull.go b/commands/pull.go
index eefcc641..15d832fe 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -2,6 +2,7 @@ package commands
import (
"errors"
+ "fmt"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/repository"
)
@@ -16,9 +17,67 @@ func runPull(repo repository.Repo, args []string) error {
remote = args[0]
}
- if err := repo.PullRefs(remote, bug.BugsRefPattern+"*", bug.BugsRemoteRefPattern+"*"); err != nil {
+ fmt.Printf("Fetching remote ...\n\n")
+
+ if err := repo.FetchRefs(remote, bug.BugsRefPattern+"*", bug.BugsRemoteRefPattern+"*"); 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
+ }
+
+ if updated {
+ fmt.Printf("%s: %s\n", remoteBug.HumanId(), "updated")
+ }
+ }
+
return nil
}