Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/cli/alpha/internal/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ func (opts *Update) Update() error {

// Push the output branch if requested
if opts.Push {
if opts.Push {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command can work locally and not necessary we want to push the new branch
Therefore, we must to keep the option here

/hold

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Just to clarify: the outer if opts.Push guard on line 208 is preserved, so the push remains fully optional. The only change is removing the duplicate inner if opts.Push that was nested inside it (always true, since the outer block already gates on the same condition), and surfacing the checkout error that was silently discarded with _.

The push behavior is unchanged: when Push is false, none of this code runs.

out := opts.getOutputBranchName()
_ = helpers.GitCmd(opts.GitConfig, "checkout", out).Run()
if err := helpers.GitCmd(opts.GitConfig, "push", "-u", "origin", out).Run(); err != nil {
return fmt.Errorf("failed to push %s: %w", out, err)
}
out := opts.getOutputBranchName()
if err := helpers.GitCmd(opts.GitConfig, "checkout", out).Run(); err != nil {
return fmt.Errorf("failed to checkout %s: %w", out, err)
}
if err := helpers.GitCmd(opts.GitConfig, "push", "-u", "origin", out).Run(); err != nil {
return fmt.Errorf("failed to push %s: %w", out, err)
}
}

Expand Down
31 changes: 31 additions & 0 deletions internal/cli/alpha/internal/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,37 @@ exit 1`
fmt.Sprintf("checkout %s", opts.FromBranch),
))
})

It("pushes the output branch when Push is enabled", func() {
opts.Push = true
err = opts.Update()
Expect(err).ToNot(HaveOccurred())

logs, readErr := os.ReadFile(logFile)
Expect(readErr).ToNot(HaveOccurred())
s := string(logs)

out := opts.getOutputBranchName()
Expect(s).To(ContainSubstring(
fmt.Sprintf("push -u origin %s", out),
))
})

It("returns error when checkout fails before push", func() {
opts.Push = true
out := opts.getOutputBranchName()
failOnPushCheckout := fmt.Sprintf(`#!/bin/bash
echo "$@" >> "%s"
if [[ "$1" == "checkout" && "$2" == "%s" ]]; then exit 1; fi
exit 0`, logFile, out)
Expect(mockBinResponse(failOnPushCheckout, mockGit)).To(Succeed())

err = opts.Update()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(
fmt.Sprintf("failed to checkout %s", out),
))
})
})

Context("RegenerateProjectWithVersion", func() {
Expand Down