From 6ca9406554cca4301b43c4bc6d0352cbd3a50324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 21 Sep 2022 20:57:53 +0200 Subject: [PATCH] pr create: allow `git push` step to prompt on stdin --- git/git.go | 3 ++- pkg/cmd/pr/create/create.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/git/git.go b/git/git.go index 50012f49a..defeae713 100644 --- a/git/git.go +++ b/git/git.go @@ -231,11 +231,12 @@ func CommitBody(sha string) (string, error) { } // Push publishes a git ref to a remote and sets up upstream configuration -func Push(remote string, ref string, cmdOut, cmdErr io.Writer) error { +func Push(remote string, ref string, cmdIn io.ReadCloser, cmdOut, cmdErr io.Writer) error { pushCmd, err := GitCommand("push", "--set-upstream", remote, ref) if err != nil { return err } + pushCmd.Stdin = cmdIn pushCmd.Stdout = cmdOut pushCmd.Stderr = cmdErr return run.PrepareCmd(pushCmd).Run() diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 92deb469d..5d3fa416c 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -726,8 +726,9 @@ func handlePush(opts CreateOptions, ctx CreateContext) error { r := NewRegexpWriter(opts.IO.ErrOut, gitPushRegexp, "") defer r.Flush() cmdErr := r + cmdIn := opts.IO.In cmdOut := opts.IO.Out - if err := git.Push(headRemote.Name, fmt.Sprintf("HEAD:%s", ctx.HeadBranch), cmdOut, cmdErr); err != nil { + if err := git.Push(headRemote.Name, fmt.Sprintf("HEAD:%s", ctx.HeadBranch), cmdIn, cmdOut, cmdErr); err != nil { if didForkRepo && pushTries < maxPushTries { pushTries++ // first wait 2 seconds after forking, then 4s, then 6s