Skip to content

Commit 2e17851

Browse files
committed
Fix two tests
1 parent fd3041c commit 2e17851

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
@@ -2648,56 +2648,6 @@ pub fn is_remote_branch_mergeable(
26482648
Ok(mergeable)
26492649
}
26502650

2651-
pub fn is_virtual_branch_mergeable(
2652-
project_repository: &project_repository::Repository,
2653-
branch_id: BranchId,
2654-
) -> Result<bool> {
2655-
let vb_state = project_repository.project().virtual_branches();
2656-
let branch = vb_state.get_branch(branch_id)?;
2657-
if branch.applied {
2658-
return Ok(true);
2659-
}
2660-
2661-
let default_target = vb_state.get_default_target()?;
2662-
// determine if this branch is up to date with the target/base
2663-
let merge_base = project_repository
2664-
.repo()
2665-
.merge_base(default_target.sha, branch.head)
2666-
.context("failed to find merge base")?;
2667-
2668-
if merge_base != default_target.sha {
2669-
return Ok(false);
2670-
}
2671-
2672-
let branch_commit = project_repository
2673-
.repo()
2674-
.find_commit(branch.head)
2675-
.context("failed to find branch commit")?;
2676-
2677-
let target_commit = project_repository
2678-
.repo()
2679-
.find_commit(default_target.sha)
2680-
.context("failed to find target commit")?;
2681-
2682-
let base_tree = find_base_tree(project_repository.repo(), &branch_commit, &target_commit)?;
2683-
2684-
let wd_tree = project_repository.repo().get_wd_tree()?;
2685-
2686-
// determine if this tree is mergeable
2687-
let branch_tree = project_repository
2688-
.repo()
2689-
.find_tree(branch.tree)
2690-
.context("failed to find branch tree")?;
2691-
2692-
let is_mergeable = !project_repository
2693-
.repo()
2694-
.merge_trees(&base_tree, &branch_tree, &wd_tree, None)
2695-
.context("failed to merge trees")?
2696-
.has_conflicts();
2697-
2698-
Ok(is_mergeable)
2699-
}
2700-
27012651
// this function takes a list of file ownership from a "from" commit and "moves"
27022652
// those changes to a "to" commit in a branch. This allows users to drag changes
27032653
// 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
{
@@ -489,10 +469,6 @@ mod applied_branch {
489469
assert_eq!(branches[0].commits.len(), 1);
490470
assert!(!branches[0].commits[0].is_remote);
491471
assert!(!branches[0].commits[0].is_integrated);
492-
assert!(controller
493-
.can_apply_virtual_branch(*project_id, branch_id)
494-
.await
495-
.unwrap());
496472
}
497473
}
498474

@@ -570,10 +546,6 @@ mod applied_branch {
570546
assert!(!branches[0].commits[0].is_integrated);
571547
assert!(branches[0].commits[1].is_remote);
572548
assert!(!branches[0].commits[1].is_integrated);
573-
assert!(controller
574-
.can_apply_virtual_branch(*project_id, branch_id)
575-
.await
576-
.unwrap());
577549
}
578550
}
579551
}
@@ -633,10 +605,6 @@ mod applied_branch {
633605
assert!(branches[0].base_current);
634606
assert_eq!(branches[0].files.len(), 1);
635607
assert_eq!(branches[0].commits.len(), 1);
636-
assert!(controller
637-
.can_apply_virtual_branch(*project_id, branch_id)
638-
.await
639-
.unwrap());
640608
}
641609

642610
{
@@ -734,10 +702,6 @@ mod applied_branch {
734702
assert!(branches[0].base_current);
735703
assert_eq!(branches[0].files.len(), 1);
736704
assert_eq!(branches[0].commits.len(), 0);
737-
assert!(controller
738-
.can_apply_virtual_branch(*project_id, branch_id)
739-
.await
740-
.unwrap());
741705
}
742706

743707
{

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},
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;
@@ -1181,6 +1180,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
11811180
Ok(())
11821181
}
11831182

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

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