fix(sdlc): skip branch push when no origin remote exists
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

The fatal push+retry logic added in the git flow hardening broke tests
that use local-only git repos without an origin remote. Check for the
origin remote before attempting to push, preserving the fatal behavior
in production (where origin always exists) while allowing local/test
contexts to proceed without a remote.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jordan 2026-02-10 21:03:49 -07:00
parent b6e778d5ab
commit f85fa181cf

View File

@ -52,20 +52,25 @@ var branchCreateCmd = &cobra.Command{
}
}
pushCmd := exec.Command("git", "push", "origin", "HEAD")
pushCmd.Dir = root
if _, err := pushCmd.CombinedOutput(); err != nil {
// Retry once — transient Gitea failures are common
time.Sleep(2 * time.Second)
retryCmd := exec.Command("git", "push", "origin", "HEAD")
retryCmd.Dir = root
if retryOut, retryErr := retryCmd.CombinedOutput(); retryErr != nil {
// Roll back the local commit so state doesn't diverge
rollbackCmd := exec.Command("git", "reset", "--soft", "HEAD~1")
rollbackCmd.Dir = root
_ = rollbackCmd.Run()
return fmt.Errorf("failed to push branch state to remote (branch not created): %s: %w",
strings.TrimSpace(string(retryOut)), retryErr)
// Only push if origin remote exists (skip in local-only/test contexts)
hasOrigin := exec.Command("git", "remote", "get-url", "origin")
hasOrigin.Dir = root
if hasOrigin.Run() == nil {
pushCmd := exec.Command("git", "push", "origin", "HEAD")
pushCmd.Dir = root
if _, err := pushCmd.CombinedOutput(); err != nil {
// Retry once — transient Gitea failures are common
time.Sleep(2 * time.Second)
retryCmd := exec.Command("git", "push", "origin", "HEAD")
retryCmd.Dir = root
if retryOut, retryErr := retryCmd.CombinedOutput(); retryErr != nil {
// Roll back the local commit so state doesn't diverge
rollbackCmd := exec.Command("git", "reset", "--soft", "HEAD~1")
rollbackCmd.Dir = root
_ = rollbackCmd.Run()
return fmt.Errorf("failed to push branch state to remote (branch not created): %s: %w",
strings.TrimSpace(string(retryOut)), retryErr)
}
}
}