Allow user input for git fetch in repo sync
This commit is contained in:
parent
3b20dfc032
commit
a8492bb0ea
2 changed files with 14 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/cli/cli/v2/git"
|
||||
"github.com/cli/cli/v2/pkg/iostreams"
|
||||
)
|
||||
|
||||
type gitClient interface {
|
||||
|
|
@ -20,7 +21,9 @@ type gitClient interface {
|
|||
ResetHard(string) error
|
||||
}
|
||||
|
||||
type gitExecuter struct{}
|
||||
type gitExecuter struct {
|
||||
io *iostreams.IOStreams
|
||||
}
|
||||
|
||||
func (g *gitExecuter) BranchRemote(branch string) (string, error) {
|
||||
args := []string{"rev-parse", "--symbolic-full-name", "--abbrev-ref", fmt.Sprintf("%s@{u}", branch)}
|
||||
|
|
@ -64,11 +67,14 @@ func (g *gitExecuter) CurrentBranch() (string, error) {
|
|||
}
|
||||
|
||||
func (g *gitExecuter) Fetch(remote, ref string) error {
|
||||
args := []string{"fetch", remote, ref}
|
||||
args := []string{"fetch", "-q", remote, ref}
|
||||
cmd, err := git.GitCommand(args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.Stdin = g.io.In
|
||||
cmd.Stdout = g.io.Out
|
||||
cmd.Stderr = g.io.ErrOut
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func NewCmdSync(f *cmdutil.Factory, runF func(*SyncOptions) error) *cobra.Comman
|
|||
IO: f.IOStreams,
|
||||
BaseRepo: f.BaseRepo,
|
||||
Remotes: f.Remotes,
|
||||
Git: &gitExecuter{},
|
||||
Git: &gitExecuter{io: f.IOStreams},
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
|
|
@ -134,6 +134,11 @@ func syncLocalRepo(opts *SyncOptions) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Git fetch might require input from user, so do it before starting progess indicator.
|
||||
if err := opts.Git.Fetch(remote, fmt.Sprintf("refs/heads/%s", opts.Branch)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts.IO.StartProgressIndicator()
|
||||
err = executeLocalRepoSync(srcRepo, remote, opts)
|
||||
opts.IO.StopProgressIndicator()
|
||||
|
|
@ -232,10 +237,6 @@ func executeLocalRepoSync(srcRepo ghrepo.Interface, remote string, opts *SyncOpt
|
|||
branch := opts.Branch
|
||||
useForce := opts.Force
|
||||
|
||||
if err := git.Fetch(remote, fmt.Sprintf("refs/heads/%s", branch)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hasLocalBranch := git.HasLocalBranch(branch)
|
||||
if hasLocalBranch {
|
||||
branchRemote, err := git.BranchRemote(branch)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue