Skip to content

Commit a8492bb

Browse files
committed
Allow user input for git fetch in repo sync
1 parent 3b20dfc commit a8492bb

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pkg/cmd/repo/sync/git.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/cli/cli/v2/git"
8+
"github.com/cli/cli/v2/pkg/iostreams"
89
)
910

1011
type gitClient interface {
@@ -20,7 +21,9 @@ type gitClient interface {
2021
ResetHard(string) error
2122
}
2223

23-
type gitExecuter struct{}
24+
type gitExecuter struct {
25+
io *iostreams.IOStreams
26+
}
2427

2528
func (g *gitExecuter) BranchRemote(branch string) (string, error) {
2629
args := []string{"rev-parse", "--symbolic-full-name", "--abbrev-ref", fmt.Sprintf("%s@{u}", branch)}
@@ -64,11 +67,14 @@ func (g *gitExecuter) CurrentBranch() (string, error) {
6467
}
6568

6669
func (g *gitExecuter) Fetch(remote, ref string) error {
67-
args := []string{"fetch", remote, ref}
70+
args := []string{"fetch", "-q", remote, ref}
6871
cmd, err := git.GitCommand(args...)
6972
if err != nil {
7073
return err
7174
}
75+
cmd.Stdin = g.io.In
76+
cmd.Stdout = g.io.Out
77+
cmd.Stderr = g.io.ErrOut
7278
return cmd.Run()
7379
}
7480

pkg/cmd/repo/sync/sync.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewCmdSync(f *cmdutil.Factory, runF func(*SyncOptions) error) *cobra.Comman
3434
IO: f.IOStreams,
3535
BaseRepo: f.BaseRepo,
3636
Remotes: f.Remotes,
37-
Git: &gitExecuter{},
37+
Git: &gitExecuter{io: f.IOStreams},
3838
}
3939

4040
cmd := &cobra.Command{
@@ -134,6 +134,11 @@ func syncLocalRepo(opts *SyncOptions) error {
134134
}
135135
}
136136

137+
// Git fetch might require input from user, so do it before starting progess indicator.
138+
if err := opts.Git.Fetch(remote, fmt.Sprintf("refs/heads/%s", opts.Branch)); err != nil {
139+
return err
140+
}
141+
137142
opts.IO.StartProgressIndicator()
138143
err = executeLocalRepoSync(srcRepo, remote, opts)
139144
opts.IO.StopProgressIndicator()
@@ -232,10 +237,6 @@ func executeLocalRepoSync(srcRepo ghrepo.Interface, remote string, opts *SyncOpt
232237
branch := opts.Branch
233238
useForce := opts.Force
234239

235-
if err := git.Fetch(remote, fmt.Sprintf("refs/heads/%s", branch)); err != nil {
236-
return err
237-
}
238-
239240
hasLocalBranch := git.HasLocalBranch(branch)
240241
if hasLocalBranch {
241242
branchRemote, err := git.BranchRemote(branch)

0 commit comments

Comments
 (0)