fix(sdlc): skip branch push when no origin remote exists
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
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:
parent
b6e778d5ab
commit
f85fa181cf
@ -52,20 +52,25 @@ var branchCreateCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pushCmd := exec.Command("git", "push", "origin", "HEAD")
|
// Only push if origin remote exists (skip in local-only/test contexts)
|
||||||
pushCmd.Dir = root
|
hasOrigin := exec.Command("git", "remote", "get-url", "origin")
|
||||||
if _, err := pushCmd.CombinedOutput(); err != nil {
|
hasOrigin.Dir = root
|
||||||
// Retry once — transient Gitea failures are common
|
if hasOrigin.Run() == nil {
|
||||||
time.Sleep(2 * time.Second)
|
pushCmd := exec.Command("git", "push", "origin", "HEAD")
|
||||||
retryCmd := exec.Command("git", "push", "origin", "HEAD")
|
pushCmd.Dir = root
|
||||||
retryCmd.Dir = root
|
if _, err := pushCmd.CombinedOutput(); err != nil {
|
||||||
if retryOut, retryErr := retryCmd.CombinedOutput(); retryErr != nil {
|
// Retry once — transient Gitea failures are common
|
||||||
// Roll back the local commit so state doesn't diverge
|
time.Sleep(2 * time.Second)
|
||||||
rollbackCmd := exec.Command("git", "reset", "--soft", "HEAD~1")
|
retryCmd := exec.Command("git", "push", "origin", "HEAD")
|
||||||
rollbackCmd.Dir = root
|
retryCmd.Dir = root
|
||||||
_ = rollbackCmd.Run()
|
if retryOut, retryErr := retryCmd.CombinedOutput(); retryErr != nil {
|
||||||
return fmt.Errorf("failed to push branch state to remote (branch not created): %s: %w",
|
// Roll back the local commit so state doesn't diverge
|
||||||
strings.TrimSpace(string(retryOut)), retryErr)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user