-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force-checkout remote branch to fix unrelated histories #228
Changes from all commits
51a2cdd
ca25547
a7455e5
5bb21d6
1c64132
85cdf57
ae21614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,14 +99,19 @@ func checkoutWithCustomRetry(gitCmd git.Git, arg string, retry fallbackRetry) er | |
return nil | ||
} | ||
|
||
func fetchInitialBranch(gitCmd git.Git, remote string, branchRef string, fetchTraits fetchOptions) error { | ||
func forceCheckoutRemoteBranch(gitCmd git.Git, remote string, branchRef string, fetchTraits fetchOptions) error { | ||
branch := strings.TrimPrefix(branchRef, refsHeadsPrefix) | ||
if err := fetch(gitCmd, remote, branchRef, fetchTraits); err != nil { | ||
wErr := fmt.Errorf("failed to fetch branch (%s): %w", branchRef, err) | ||
wErr := fmt.Errorf("fetch branch %s: %w", branchRef, err) | ||
return fmt.Errorf("%v: %w", wErr, errors.New("please make sure the branch still exists")) | ||
} | ||
|
||
if err := checkoutWithCustomRetry(gitCmd, branch, nil); err != nil { | ||
|
||
remoteBranch := fmt.Sprintf("%s/%s", remote, branch) | ||
// -B: create the branch if it doesn't exist, reset if it does | ||
// The latter is important in persistent environments because shallow-fetching only fetches 1 commit, | ||
// so the next run would see unrelated histories after shallow-fetching another single commit. | ||
err := runner.Run(gitCmd.Checkout("-B", branch, remoteBranch)) | ||
if err != nil { | ||
return handleCheckoutError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The custom retry here adds nicer error message (a list of existing branch names), but if a branch doesn't exist, I think it fails in the fetch step above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have vague memories about this error handling, I think the project scanner uses it. Probably the returned branches are propagated to the UI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Unfortunately" I found references to it even in the frontend code, so this is still used: https://github.com/bitrise-io/bitrise-website/blob/2815eaa08f3d1d31bd782535dffa56c69a549dae/app/javascript/pages/AddNewApp/stages/ProjectConfig/ProjectConfig.types.ts#L11 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted |
||
listBranches(gitCmd), | ||
checkoutFailedTag, | ||
|
@@ -116,16 +121,6 @@ func fetchInitialBranch(gitCmd git.Git, remote string, branchRef string, fetchTr | |
) | ||
} | ||
|
||
// Update branch: 'git fetch' followed by a 'git merge' is the same as 'git pull'. | ||
remoteBranch := fmt.Sprintf("%s/%s", remote, branch) | ||
if err := runner.Run(gitCmd.Merge(remoteBranch)); err != nil { | ||
return newStepError( | ||
"update_branch_failed", | ||
fmt.Errorf("updating branch (%s) failed: %w", branch, err), | ||
"Updating branch failed", | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming is hard 😵💫