Skip to content

Commit 53899e7

Browse files
committed
Fast-forward instead of force push to base branch
1 parent 4393f29 commit 53899e7

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/bors/handlers/trybuild.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async fn attempt_merge(
146146

147147
// First set the try branch to our base commit (either the selected parent or the main branch).
148148
client
149-
.set_branch_to_sha(TRY_MERGE_BRANCH_NAME, base_sha)
149+
.set_branch_to_sha(TRY_MERGE_BRANCH_NAME, base_sha, true)
150150
.await
151151
.map_err(|error| anyhow!("Cannot set try merge branch to {}: {error:?}", base_sha.0))?;
152152

@@ -177,7 +177,7 @@ async fn run_try_build(
177177
parent_sha: CommitSha,
178178
) -> anyhow::Result<()> {
179179
client
180-
.set_branch_to_sha(TRY_BRANCH_NAME, &commit_sha)
180+
.set_branch_to_sha(TRY_BRANCH_NAME, &commit_sha, true)
181181
.await
182182
.map_err(|error| anyhow!("Cannot set try branch to main branch: {error:?}"))?;
183183

src/bors/merge_queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub async fn handle_merge_queue(ctx: Arc<BorsContext>) -> anyhow::Result<()> {
7070
BuildStatus::Success => {
7171
match repo
7272
.client
73-
.set_branch_to_sha(&pr.base_branch, &commit_sha)
73+
.set_branch_to_sha(&pr.base_branch, &commit_sha, false)
7474
.await
7575
{
7676
Ok(()) => {
@@ -197,7 +197,7 @@ async fn start_auto_build(
197197
MergeResult::Success(merge_sha) => {
198198
// 2. Push merge commit to `AUTO_BRANCH_NAME` where CI runs
199199
client
200-
.set_branch_to_sha(AUTO_BRANCH_NAME, &merge_sha)
200+
.set_branch_to_sha(AUTO_BRANCH_NAME, &merge_sha, true)
201201
.await?;
202202

203203
// 3. Record the build in the database
@@ -276,7 +276,7 @@ async fn attempt_merge(
276276

277277
// Reset auto merge branch to point to base branch
278278
client
279-
.set_branch_to_sha(AUTO_MERGE_BRANCH_NAME, base_sha)
279+
.set_branch_to_sha(AUTO_MERGE_BRANCH_NAME, base_sha, true)
280280
.await
281281
.map_err(|error| anyhow!("Cannot set auto merge branch to {}: {error:?}", base_sha.0))?;
282282

src/github/api/client.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,14 @@ impl GithubRepositoryClient {
139139
}
140140

141141
/// Set the given branch to a commit with the given `sha`.
142-
pub async fn set_branch_to_sha(&self, branch: &str, sha: &CommitSha) -> anyhow::Result<()> {
142+
pub async fn set_branch_to_sha(
143+
&self,
144+
branch: &str,
145+
sha: &CommitSha,
146+
force: bool,
147+
) -> anyhow::Result<()> {
143148
perform_network_request_with_retry("set_branch_to_sha", || async {
144-
Ok(set_branch_to_commit(self, branch.to_string(), sha).await?)
149+
Ok(set_branch_to_commit(self, branch.to_string(), sha, force).await?)
145150
})
146151
.await?
147152
}

src/github/api/operations.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ pub async fn merge_branches(
8888
}
8989
}
9090

91-
/// Forcefully updates the branch to the given commit `sha`.
91+
/// Updates the branch to the given commit `sha`.
9292
/// If the branch does not exist yet, it instead attempts to create it.
9393
pub async fn set_branch_to_commit(
9494
repo: &GithubRepositoryClient,
9595
branch_name: String,
9696
sha: &CommitSha,
97+
force: bool,
9798
) -> Result<(), BranchUpdateError> {
9899
// Fast-path: assume that the branch exists
99-
match update_branch(repo, branch_name.clone(), sha).await {
100+
match update_branch(repo, branch_name.clone(), sha, force).await {
100101
Ok(_) => Ok(()),
101102
Err(BranchUpdateError::BranchNotFound(_)) => {
102103
// Branch does not exist yet, try to create it
@@ -132,11 +133,12 @@ pub enum BranchUpdateError {
132133
Custom(String),
133134
}
134135

135-
/// Force update the branch with the given `branch_name` to the given `sha`.
136+
/// Update the branch with the given `branch_name` to the given `sha`.
136137
async fn update_branch(
137138
repo: &GithubRepositoryClient,
138139
branch_name: String,
139140
sha: &CommitSha,
141+
force: bool,
140142
) -> Result<(), BranchUpdateError> {
141143
let url = format!(
142144
"/repos/{}/git/refs/{}",
@@ -152,7 +154,7 @@ async fn update_branch(
152154
url.as_str(),
153155
Some(&serde_json::json!({
154156
"sha": sha.as_ref(),
155-
"force": true
157+
"force": force
156158
})),
157159
)
158160
.await?;

0 commit comments

Comments
 (0)