From 96372e5ac83f8dbf880ad21c9a881d4ce030dd61 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 24 Oct 2022 15:02:24 -0700 Subject: [PATCH 1/2] use new GitClient in issue develop --- pkg/cmd/issue/develop/develop.go | 16 +++++++++------- pkg/cmd/issue/develop/develop_test.go | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/issue/develop/develop.go b/pkg/cmd/issue/develop/develop.go index eeda7bd19..4dcea2b12 100644 --- a/pkg/cmd/issue/develop/develop.go +++ b/pkg/cmd/issue/develop/develop.go @@ -1,6 +1,7 @@ package develop import ( + ctx "context" "fmt" "net/http" @@ -10,7 +11,6 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" - "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -20,6 +20,7 @@ import ( type DevelopOptions struct { HttpClient func() (*http.Client, error) + GitClient *git.Client Config func() (config.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) @@ -37,6 +38,7 @@ func NewCmdDevelop(f *cmdutil.Factory, runF func(*DevelopOptions) error) *cobra. opts := &DevelopOptions{ IO: f.IOStreams, HttpClient: f.HttpClient, + GitClient: f.GitClient, Config: f.Config, BaseRepo: f.BaseRepo, Remotes: f.Remotes, @@ -254,12 +256,12 @@ func checkoutBranch(opts *DevelopOptions, baseRepo ghrepo.Interface, checkoutBra return err } - if git.HasLocalBranch(checkoutBranch) { - if err := git.CheckoutBranch(checkoutBranch); err != nil { + if opts.GitClient.HasLocalBranch(ctx.Background(), checkoutBranch) { + if err := opts.GitClient.CheckoutBranch(ctx.Background(), checkoutBranch); err != nil { return err } } else { - gitFetch, err := git.GitCommand("fetch", "origin", fmt.Sprintf("+refs/heads/%[1]s:refs/remotes/origin/%[1]s", checkoutBranch)) + gitFetch, err := opts.GitClient.Command(ctx.Background(), "fetch", "origin", fmt.Sprintf("+refs/heads/%[1]s:refs/remotes/origin/%[1]s", checkoutBranch)) if err != nil { return err @@ -267,16 +269,16 @@ func checkoutBranch(opts *DevelopOptions, baseRepo ghrepo.Interface, checkoutBra gitFetch.Stdout = opts.IO.Out gitFetch.Stderr = opts.IO.ErrOut - err = run.PrepareCmd(gitFetch).Run() + err = gitFetch.Run() if err != nil { return err } - if err := git.CheckoutNewBranch(baseRemote.Name, checkoutBranch); err != nil { + if err := opts.GitClient.CheckoutNewBranch(ctx.Background(), baseRemote.Name, checkoutBranch); err != nil { return err } } - if err := git.Pull(baseRemote.Name, checkoutBranch); err != nil { + if err := opts.GitClient.Pull(ctx.Background(), baseRemote.Name, checkoutBranch); err != nil { _, _ = fmt.Fprintf(opts.IO.ErrOut, "%s warning: not possible to fast-forward to: %q\n", opts.IO.ColorScheme().WarningIcon(), checkoutBranch) } diff --git a/pkg/cmd/issue/develop/develop_test.go b/pkg/cmd/issue/develop/develop_test.go index 20d34cce0..2bf11e0d7 100644 --- a/pkg/cmd/issue/develop/develop_test.go +++ b/pkg/cmd/issue/develop/develop_test.go @@ -569,6 +569,8 @@ func Test_developRun(t *testing.T) { return remotes, nil } + opts.GitClient = &git.Client{GitPath: "some/path/git"} + cmdStubs, cmdTeardown := run.Stub() defer cmdTeardown(t) if tt.runStubs != nil { From afecf7e5d02d0344221153e47b09c58338176cfe Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 24 Oct 2022 15:23:40 -0700 Subject: [PATCH 2/2] use tableprinter in issue develop --- pkg/cmd/issue/develop/develop.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/issue/develop/develop.go b/pkg/cmd/issue/develop/develop.go index 4dcea2b12..5d2fa2d6a 100644 --- a/pkg/cmd/issue/develop/develop.go +++ b/pkg/cmd/issue/develop/develop.go @@ -11,10 +11,10 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/utils" "github.com/spf13/cobra" ) @@ -188,12 +188,12 @@ func issueMetadata(issueSelector string, issueRepoSelector string, baseRepo ghre func printLinkedBranches(io *iostreams.IOStreams, branches []api.LinkedBranch) { cs := io.ColorScheme() - table := utils.NewTablePrinter(io) + table := tableprinter.New(io) for _, branch := range branches { - table.AddField(branch.BranchName, nil, cs.ColorFromString("cyan")) - if table.IsTTY() { - table.AddField(branch.Url(), nil, nil) + table.AddField(branch.BranchName, tableprinter.WithColor(cs.ColorFromString("cyan"))) + if io.CanPrompt() { + table.AddField(branch.Url()) } table.EndRow() }