From f85fa181cf0531841e8449c6e053d3c89253647e Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 10 Feb 2026 21:03:49 -0700 Subject: [PATCH] fix(sdlc): skip branch push when no origin remote exists 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 --- cmd/sdlc/cmd_branch.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cmd/sdlc/cmd_branch.go b/cmd/sdlc/cmd_branch.go index e5f7e8c..edeed44 100644 --- a/cmd/sdlc/cmd_branch.go +++ b/cmd/sdlc/cmd_branch.go @@ -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) + } } }