aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 21:51:27 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 21:51:27 +0200
commit35d64e4f9e3e0a0ffd041e430a64650bb8ea71fa (patch)
tree802ed0c56ab5b09fb29800a147e3fcf3d8557e55
parent1779a0f3b92d58654b43444addeaf437a64d77a8 (diff)
downloadgit-bug-35d64e4f9e3e0a0ffd041e430a64650bb8ea71fa.tar.gz
fix push/pull
-rw-r--r--bug/bug.go1
-rw-r--r--commands/pull.go2
-rw-r--r--repository/git.go20
-rw-r--r--repository/mock_repo.go2
-rw-r--r--repository/repo.go2
5 files changed, 20 insertions, 7 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 8b5f4be9..658d73e1 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -8,6 +8,7 @@ import (
)
const BugsRefPattern = "refs/bugs/"
+const BugsRemoteRefPattern = "refs/remote/%s/bugs/"
// Bug hold the data of a bug thread, organized in a way close to
// how it will be persisted inside Git. This is the datastructure
diff --git a/commands/pull.go b/commands/pull.go
index b3541c0f..105fce9c 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -17,7 +17,7 @@ func pull(repo repository.Repo, args []string) error {
remote = args[0]
}
- if err := repo.PullRefs(remote, bug.BugsRefPattern+"*"); err != nil {
+ if err := repo.PullRefs(remote, bug.BugsRefPattern+"*", bug.BugsRemoteRefPattern+"*"); err != nil {
return err
}
return nil
diff --git a/repository/git.go b/repository/git.go
index 8c20d0b8..92c7bb63 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/MichaelMure/git-bug/util"
"io"
+ "os"
"os/exec"
"strings"
)
@@ -58,6 +59,11 @@ func (repo *GitRepo) runGitCommand(args ...string) (string, error) {
return repo.runGitCommandWithStdin(nil, args...)
}
+// Run the given git command using the same stdin, stdout, and stderr as the review tool.
+func (repo *GitRepo) runGitCommandInline(args ...string) error {
+ return repo.runGitCommandWithIO(os.Stdin, os.Stdout, os.Stderr, args...)
+}
+
// NewGitRepo determines if the given working directory is inside of a git repository,
// and returns the corresponding GitRepo instance if it is.
func NewGitRepo(path string) (*GitRepo, error) {
@@ -99,9 +105,14 @@ func (repo *GitRepo) GetCoreEditor() (string, error) {
}
// PullRefs pull git refs from a remote
-func (repo *GitRepo) PullRefs(remote string, refPattern string) error {
- fetchRefSpec := fmt.Sprintf("+%s:%s", refPattern, refPattern)
- _, err := repo.runGitCommand("fetch", remote, fetchRefSpec)
+func (repo *GitRepo) PullRefs(remote, refPattern, remoteRefPattern string) error {
+ remoteRefSpec := fmt.Sprintf(remoteRefPattern, remote)
+ fetchRefSpec := fmt.Sprintf("%s:%s", refPattern, remoteRefSpec)
+ err := repo.runGitCommandInline("fetch", remote, fetchRefSpec)
+
+ if err != nil {
+ return fmt.Errorf("failed to pull from the remote '%s': %v", remote, err)
+ }
// TODO: merge new data
@@ -112,7 +123,8 @@ func (repo *GitRepo) PullRefs(remote string, refPattern string) error {
func (repo *GitRepo) PushRefs(remote string, refPattern string) error {
// The push is liable to fail if the user forgot to do a pull first, so
// we treat errors as user errors rather than fatal errors.
- _, err := repo.runGitCommand("push", remote, refPattern)
+ err := repo.runGitCommandInline("push", remote, refPattern)
+
if err != nil {
return fmt.Errorf("failed to push to the remote '%s': %v", remote, err)
}
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index e747eb24..f9b070b4 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -35,7 +35,7 @@ func (r *mockRepoForTest) PushRefs(remote string, refPattern string) error {
return nil
}
-func (r *mockRepoForTest) PullRefs(remote string, refPattern string) error {
+func (r *mockRepoForTest) PullRefs(remote string, refPattern string, remoteRefPattern string) error {
return nil
}
diff --git a/repository/repo.go b/repository/repo.go
index 3a30128f..a58f35d9 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -18,7 +18,7 @@ type Repo interface {
GetCoreEditor() (string, error)
// PullRefs pull git refs from a remote
- PullRefs(remote string, refPattern string) error
+ PullRefs(remote string, refPattern string, remoteRefPattern string) error
// PushRefs push git refs to a remote
PushRefs(remote string, refPattern string) error