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
27 changes: 27 additions & 0 deletions gitclone/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,33 @@ func createCheckoutStrategy(checkoutMethod CheckoutMethod, cfg Config, patchFile

return checkoutCommit{
params: *params,
fallbackCheckout: func(gitCmd git.Git) error {
log.Warnf("Using commit checkout strategy with PR source branch")

if cfg.Branch == "" || cfg.Commit == "" {
return fmt.Errorf("inconsistent checkout strategy and checkout params: branch=%s, commit=%s", cfg.Branch, cfg.Commit)
}

branchRef := refsHeadsPrefix + cfg.Branch
commitCheckoutFallbackFetchOpts := selectFetchOptions(CheckoutCommitMethod, cfg.CloneDepth, cfg.FetchTags, cfg.UpdateSubmodules, len(cfg.SparseDirectories) != 0)
commitCheckoutFallbackFallback := selectFallbacks(CheckoutCommitMethod, commitCheckoutFallbackFetchOpts)

prRepositoryURL := ""
if isFork(cfg.RepositoryURL, cfg.PRSourceRepositoryURL) {
prRepositoryURL = cfg.PRSourceRepositoryURL
}

params, err := NewCommitParams(cfg.Commit, branchRef, prRepositoryURL)
if err != nil {
return err
}

commitCheckoutFallbackCheckoutMethod := checkoutCommit{
params: *params,
}

return commitCheckoutFallbackCheckoutMethod.do(gitCmd, commitCheckoutFallbackFetchOpts, commitCheckoutFallbackFallback)
},
}, nil
}
case CheckoutForkCommitMethod:
Expand Down
5 changes: 2 additions & 3 deletions gitclone/checkout_method_pr_auto_merge_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gitclone
import (
"fmt"
"strings"

"github.com/bitrise-io/go-utils/command/git"
"github.com/bitrise-io/go-utils/log"
)
Expand Down Expand Up @@ -42,9 +42,8 @@ type fallbackCheckoutFunc func(gitCmd git.Git) error

func (c checkoutPRMergeRef) do(gitCmd git.Git, fetchOpts fetchOptions, fallback fallbackRetry) error {
if err := c.performCheckout(gitCmd, fetchOpts, fallback); err != nil {
log.Warnf("Failed to checkout PR merge branch: %s", err)

if c.fallbackCheckout != nil {
log.Warnf("Failed to checkout PR merge branch: %s", err)
return c.fallbackCheckout(gitCmd)
}
return err
Expand Down
15 changes: 14 additions & 1 deletion gitclone/checkout_method_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/bitrise-io/go-utils/command/git"
"github.com/bitrise-io/go-utils/log"
)

// checkoutNone
Expand Down Expand Up @@ -40,10 +41,22 @@ func NewCommitParams(commit, branchRef, sourceRepoURL string) (*CommitParams, er

// checkoutCommit
type checkoutCommit struct {
params CommitParams
params CommitParams
fallbackCheckout fallbackCheckoutFunc
}

func (c checkoutCommit) do(gitCmd git.Git, fetchOptions fetchOptions, fallback fallbackRetry) error {
if err := c.performCheckout(gitCmd, fetchOptions, fallback); err != nil {
if c.fallbackCheckout != nil {
log.Warnf("Failed to checkout commit: %s", err)
return c.fallbackCheckout(gitCmd)
}
return err
}
return nil
}

func (c checkoutCommit) performCheckout(gitCmd git.Git, fetchOptions fetchOptions, fallback fallbackRetry) error {
remote := originRemoteName
if c.params.SourceRepoURL != "" {
remote = forkRemoteName
Expand Down