Skip to content

Commit 7f6fecd

Browse files
committed
Fix two tests
1 parent ebbb372 commit 7f6fecd

File tree

9 files changed

+5
-145
lines changed

9 files changed

+5
-145
lines changed

app/src/lib/vbranches/virtualBranch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ export class VirtualBranchService {
5858
tap((branches) => {
5959
branches.forEach((branch) => {
6060
branch.files.sort((a) => (a.conflicted ? -1 : 0));
61-
branch.isMergeable = invoke<boolean>('can_apply_virtual_branch', {
62-
projectId: projectId,
63-
branchId: branch.id
64-
});
61+
// This is always true now
62+
branch.isMergeable = Promise.resolve(true);
6563
});
6664
this.fresh$.next(); // Notification for fresh reload
6765
}),

crates/gitbutler-core/src/virtual_branches/controller.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ impl Controller {
7373
.can_apply_remote_branch(project_id, branch_name)
7474
}
7575

76-
pub async fn can_apply_virtual_branch(
77-
&self,
78-
project_id: ProjectId,
79-
branch_id: BranchId,
80-
) -> Result<bool> {
81-
self.inner(project_id)
82-
.await
83-
.can_apply_virtual_branch(project_id, branch_id)
84-
}
85-
8676
pub async fn list_virtual_branches(
8777
&self,
8878
project_id: ProjectId,
@@ -473,16 +463,6 @@ impl ControllerInner {
473463
super::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into)
474464
}
475465

476-
pub fn can_apply_virtual_branch(
477-
&self,
478-
project_id: ProjectId,
479-
branch_id: BranchId,
480-
) -> Result<bool> {
481-
let project = self.projects.get(project_id)?;
482-
let project_repository = project_repository::Repository::open(&project)?;
483-
super::is_virtual_branch_mergeable(&project_repository, branch_id).map_err(Into::into)
484-
}
485-
486466
pub async fn list_virtual_branches(
487467
&self,
488468
project_id: ProjectId,

crates/gitbutler-core/src/virtual_branches/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn get_workspace_head(
6060
let merge_base = repo.merge_base(first_branch.head, merge_parent)?;
6161
workspace_tree = repo.find_commit(merge_base)?.tree()?;
6262
} else {
63-
for branch in &applied_branches {
63+
for branch in dbg!(&applied_branches) {
6464
let branch_tree = repo.find_commit(branch.head)?.tree()?;
6565
let merge_tree = repo.find_commit(target.sha)?.tree()?;
6666
let mut index = repo.merge_trees(&merge_tree, &workspace_tree, &branch_tree, None)?;

crates/gitbutler-core/src/virtual_branches/virtual.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,56 +2632,6 @@ pub fn is_remote_branch_mergeable(
26322632
Ok(mergeable)
26332633
}
26342634

2635-
pub fn is_virtual_branch_mergeable(
2636-
project_repository: &project_repository::Repository,
2637-
branch_id: BranchId,
2638-
) -> Result<bool> {
2639-
let vb_state = project_repository.project().virtual_branches();
2640-
let branch = vb_state.get_branch(branch_id)?;
2641-
if branch.applied {
2642-
return Ok(true);
2643-
}
2644-
2645-
let default_target = vb_state.get_default_target()?;
2646-
// determine if this branch is up to date with the target/base
2647-
let merge_base = project_repository
2648-
.repo()
2649-
.merge_base(default_target.sha, branch.head)
2650-
.context("failed to find merge base")?;
2651-
2652-
if merge_base != default_target.sha {
2653-
return Ok(false);
2654-
}
2655-
2656-
let branch_commit = project_repository
2657-
.repo()
2658-
.find_commit(branch.head)
2659-
.context("failed to find branch commit")?;
2660-
2661-
let target_commit = project_repository
2662-
.repo()
2663-
.find_commit(default_target.sha)
2664-
.context("failed to find target commit")?;
2665-
2666-
let base_tree = find_base_tree(project_repository.repo(), &branch_commit, &target_commit)?;
2667-
2668-
let wd_tree = project_repository.repo().get_wd_tree()?;
2669-
2670-
// determine if this tree is mergeable
2671-
let branch_tree = project_repository
2672-
.repo()
2673-
.find_tree(branch.tree)
2674-
.context("failed to find branch tree")?;
2675-
2676-
let is_mergeable = !project_repository
2677-
.repo()
2678-
.merge_trees(&base_tree, &branch_tree, &wd_tree, None)
2679-
.context("failed to merge trees")?
2680-
.has_conflicts();
2681-
2682-
Ok(is_mergeable)
2683-
}
2684-
26852635
// this function takes a list of file ownership from a "from" commit and "moves"
26862636
// those changes to a "to" commit in a branch. This allows users to drag changes
26872637
// from one commit to another.

crates/gitbutler-core/tests/suite/virtual_branches/apply_virtual_branch.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ async fn deltect_conflict() {
4040
}
4141

4242
{
43-
// it should not be possible to apply the first branch
44-
assert!(!controller
45-
.can_apply_virtual_branch(*project_id, branch1_id)
46-
.await
47-
.unwrap());
48-
4943
assert!(matches!(
5044
controller
5145
.apply_virtual_branch(*project_id, branch1_id)

crates/gitbutler-core/tests/suite/virtual_branches/update_base_branch.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ mod applied_branch {
5353
assert!(!branches[0].base_current);
5454
assert_eq!(branches[0].files.len(), 1);
5555
assert_eq!(branches[0].commits.len(), 0);
56-
assert!(!controller
57-
.can_apply_virtual_branch(*project_id, branch_id)
58-
.await
59-
.unwrap());
6056
}
6157

6258
{
@@ -134,10 +130,6 @@ mod applied_branch {
134130
assert!(!branches[0].base_current);
135131
assert_eq!(branches[0].files.len(), 0);
136132
assert_eq!(branches[0].commits.len(), 1);
137-
assert!(!controller
138-
.can_apply_virtual_branch(*project_id, branch_id)
139-
.await
140-
.unwrap());
141133
}
142134

143135
{
@@ -220,10 +212,6 @@ mod applied_branch {
220212
assert!(!branches[0].base_current);
221213
assert_eq!(branches[0].files.len(), 0);
222214
assert_eq!(branches[0].commits.len(), 1);
223-
assert!(!controller
224-
.can_apply_virtual_branch(*project_id, branch_id)
225-
.await
226-
.unwrap());
227215
}
228216

229217
{
@@ -303,10 +291,6 @@ mod applied_branch {
303291
assert!(!branches[0].base_current); // TODO: should be true
304292
assert_eq!(branches[0].files.len(), 1);
305293
assert_eq!(branches[0].commits.len(), 1);
306-
assert!(!controller
307-
.can_apply_virtual_branch(*project_id, branch_id)
308-
.await
309-
.unwrap()); // TODO: should be true
310294
}
311295

312296
{
@@ -386,10 +370,6 @@ mod applied_branch {
386370
assert!(!branches[0].base_current); // TODO: should be true
387371
assert_eq!(branches[0].commits.len(), 1); // TODO: should be 2
388372
assert_eq!(branches[0].files.len(), 1);
389-
assert!(!controller
390-
.can_apply_virtual_branch(*project_id, branch_id)
391-
.await
392-
.unwrap()); // TODO: should be true
393373
}
394374

395375
{
@@ -488,10 +468,6 @@ mod applied_branch {
488468
assert_eq!(branches[0].commits.len(), 1);
489469
assert!(!branches[0].commits[0].is_remote);
490470
assert!(!branches[0].commits[0].is_integrated);
491-
assert!(controller
492-
.can_apply_virtual_branch(*project_id, branch_id)
493-
.await
494-
.unwrap());
495471
}
496472
}
497473

@@ -571,10 +547,6 @@ mod applied_branch {
571547
assert!(!branches[0].commits[0].is_integrated);
572548
assert!(branches[0].commits[1].is_remote);
573549
assert!(!branches[0].commits[1].is_integrated);
574-
assert!(controller
575-
.can_apply_virtual_branch(*project_id, branch_id)
576-
.await
577-
.unwrap());
578550
}
579551
}
580552
}
@@ -634,10 +606,6 @@ mod applied_branch {
634606
assert!(branches[0].base_current);
635607
assert_eq!(branches[0].files.len(), 1);
636608
assert_eq!(branches[0].commits.len(), 1);
637-
assert!(controller
638-
.can_apply_virtual_branch(*project_id, branch_id)
639-
.await
640-
.unwrap());
641609
}
642610

643611
{
@@ -735,10 +703,6 @@ mod applied_branch {
735703
assert!(branches[0].base_current);
736704
assert_eq!(branches[0].files.len(), 1);
737705
assert_eq!(branches[0].commits.len(), 0);
738-
assert!(controller
739-
.can_apply_virtual_branch(*project_id, branch_id)
740-
.await
741-
.unwrap());
742706
}
743707

744708
{

crates/gitbutler-core/tests/virtual_branches/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use gitbutler_core::{
2121
branch::{BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest},
2222
commit, create_virtual_branch, integrate_upstream_commits,
2323
integration::verify_branch,
24-
is_remote_branch_mergeable, is_virtual_branch_mergeable, list_remote_branches,
25-
unapply_ownership, update_branch,
24+
is_remote_branch_mergeable, list_remote_branches, unapply_ownership, update_branch,
2625
},
2726
};
2827
use pretty_assertions::assert_eq;
@@ -1180,6 +1179,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
11801179
Ok(())
11811180
}
11821181

1182+
// Verifies that we are able to detect when a remote branch is conflicting with the current applied branches.
11831183
#[test]
11841184
fn detect_mergeable_branch() -> Result<()> {
11851185
let suite = Suite::default();
@@ -1299,17 +1299,6 @@ fn detect_mergeable_branch() -> Result<()> {
12991299
};
13001300
vb_state.set_branch(branch4.clone())?;
13011301

1302-
let (branches, _) = virtual_branches::list_virtual_branches(project_repository)?;
1303-
assert_eq!(branches.len(), 4);
1304-
1305-
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
1306-
assert!(!branch1.active);
1307-
assert!(!is_virtual_branch_mergeable(project_repository, branch1.id).unwrap());
1308-
1309-
let branch2 = &branches.iter().find(|b| b.id == branch2_id).unwrap();
1310-
assert!(!branch2.active);
1311-
assert!(is_virtual_branch_mergeable(project_repository, branch2.id).unwrap());
1312-
13131302
let remotes = list_remote_branches(project_repository).expect("failed to list remotes");
13141303
let _remote1 = &remotes
13151304
.iter()

crates/gitbutler-tauri/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ fn main() {
191191
virtual_branches::commands::reset_files,
192192
virtual_branches::commands::push_virtual_branch,
193193
virtual_branches::commands::create_virtual_branch_from_branch,
194-
virtual_branches::commands::can_apply_virtual_branch,
195194
virtual_branches::commands::can_apply_remote_branch,
196195
virtual_branches::commands::list_remote_commit_files,
197196
virtual_branches::commands::reset_virtual_branch,

crates/gitbutler-tauri/src/virtual_branches.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,6 @@ pub mod commands {
277277
Ok(())
278278
}
279279

280-
#[tauri::command(async)]
281-
#[instrument(skip(handle), err(Debug))]
282-
pub async fn can_apply_virtual_branch(
283-
handle: AppHandle,
284-
project_id: ProjectId,
285-
branch_id: BranchId,
286-
) -> Result<bool, Error> {
287-
handle
288-
.state::<Controller>()
289-
.can_apply_virtual_branch(project_id, branch_id)
290-
.await
291-
.map_err(Into::into)
292-
}
293-
294280
#[tauri::command(async)]
295281
#[instrument(skip(handle), err(Debug))]
296282
pub async fn can_apply_remote_branch(

0 commit comments

Comments
 (0)