From a8492bb0eab73171b46fa2c3871a2cfb71a9bf34 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 13 Sep 2021 10:14:20 -0700 Subject: [PATCH] Allow user input for git fetch in repo sync --- pkg/cmd/repo/sync/git.go | 10 ++++++++-- pkg/cmd/repo/sync/sync.go | 11 ++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/repo/sync/git.go b/pkg/cmd/repo/sync/git.go index ffb9a4179..1ec86b053 100644 --- a/pkg/cmd/repo/sync/git.go +++ b/pkg/cmd/repo/sync/git.go @@ -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() } diff --git a/pkg/cmd/repo/sync/sync.go b/pkg/cmd/repo/sync/sync.go index c4dc72695..4e07be890 100644 --- a/pkg/cmd/repo/sync/sync.go +++ b/pkg/cmd/repo/sync/sync.go @@ -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)