consider force push preference when applying branches

This commit is contained in:
Nikita Galaiko 2023-12-15 10:56:38 +01:00 committed by GitButler
parent 5646580183
commit 2544e48216
2 changed files with 23 additions and 3 deletions

View File

@ -288,9 +288,10 @@ pub fn apply_branch(
.find_tree(merged_branch_tree_oid)
.context("failed to find tree")?;
if branch.upstream.is_some() {
// branch was pushed to upstream. create a merge commit to avoid need
// of force pushing.
let ok_with_force_push = project_repository.project().ok_with_force_push;
if branch.upstream.is_some() && !ok_with_force_push {
// branch was pushed to upstream, and user doesn't like force pushing.
// create a merge commit to avoid the need of force pushing then.
let new_branch_head = project_repository.commit(
user,

View File

@ -2613,9 +2613,19 @@ mod update_base_branch {
repository,
project_id,
controller,
projects,
..
} = Test::default();
projects
.update(&projects::UpdateRequest {
id: project_id,
ok_with_force_push: Some(false),
..Default::default()
})
.await
.unwrap();
controller
.set_base_branch(&project_id, &"refs/remotes/origin/master".parse().unwrap())
.await
@ -3659,6 +3669,15 @@ mod amend {
..
} = Test::default();
projects
.update(&projects::UpdateRequest {
id: project_id,
ok_with_force_push: Some(false),
..Default::default()
})
.await
.unwrap();
controller
.set_base_branch(&project_id, &"refs/remotes/origin/master".parse().unwrap())
.await