Skip to content

Commit 761abb9

Browse files
committed
many many changes
1 parent b189480 commit 761abb9

File tree

6 files changed

+51
-67
lines changed

6 files changed

+51
-67
lines changed

crates/gitbutler-core/src/project_repository/conflicts.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,20 @@ pub fn conflicting_files(repository: &Repository) -> Result<Vec<String>> {
9797
/// Check if `path` is conflicting in `repository`, or if `None`, check if there is any conflict.
9898
// TODO(ST): Should this not rather check the conflicting state in the index?
9999
pub fn is_conflicting(repository: &Repository, path: Option<&Path>) -> Result<bool> {
100-
let conflicts_path = repository.repo().path().join("conflicts");
101-
if !conflicts_path.exists() {
102-
return Ok(false);
103-
}
100+
let mut status_options = git2::StatusOptions::new();
101+
status_options.include_untracked(true);
104102

105-
let file = std::fs::File::open(conflicts_path)?;
106-
let reader = std::io::BufReader::new(file);
107-
// TODO(ST): This shouldn't work on UTF8 strings.
108-
let mut files = reader.lines().map_ok(PathBuf::from);
109-
if let Some(pathname) = path {
110-
// check if pathname is one of the lines in conflicts_path file
111-
for line in files {
112-
let line = line?;
113-
114-
if line == pathname {
115-
return Ok(true);
116-
}
117-
}
118-
Ok(false)
119-
} else {
120-
Ok(files.next().transpose().map(|x| x.is_some())?)
103+
if let Some(path) = path {
104+
status_options.pathspec(path);
121105
}
106+
107+
let statuses = repository.repo().statuses(Some(&mut status_options))?;
108+
109+
let conflicted = statuses
110+
.iter()
111+
.any(|status| status.status().intersects(git2::Status::CONFLICTED));
112+
113+
Ok(conflicted)
122114
}
123115

124116
// is this project still in a resolving conflict state?

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ pub fn update_base_branch<'repo>(
396396
&branch_tree,
397397
)?;
398398
if non_commited_files.is_empty() {
399+
println!("WFTFFF");
399400
// if there are no commited files, then the branch is fully merged
400401
// and we can delete it.
401402
vb_state.remove_branch(branch.id)?;
@@ -427,7 +428,7 @@ pub fn update_base_branch<'repo>(
427428
.expect("Failed to convert to real branch");
428429
unapplied_branch_names.push(unapplied_real_branch);
429430

430-
return Ok(Some(branch));
431+
return Ok(None);
431432
}
432433

433434
let branch_merge_index_tree_oid =
@@ -464,7 +465,7 @@ pub fn update_base_branch<'repo>(
464465
.expect("2 failed to convert to real branch");
465466
unapplied_branch_names.push(unapplied_real_branch);
466467

467-
return Ok(Some(branch));
468+
return Ok(None);
468469
}
469470

470471
// branch commits do not conflict with new target, so lets merge them

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Controller {
301301
project_id: ProjectId,
302302
branch_id: BranchId,
303303
name_conflict_resolution: NameConflitResolution,
304-
) -> Result<()> {
304+
) -> Result<ReferenceName> {
305305
self.inner(project_id)
306306
.await
307307
.convert_to_real_branch(project_id, branch_id, name_conflict_resolution)
@@ -771,7 +771,7 @@ impl ControllerInner {
771771
project_id: ProjectId,
772772
branch_id: BranchId,
773773
name_conflict_resolution: NameConflitResolution,
774-
) -> Result<()> {
774+
) -> Result<ReferenceName> {
775775
let _permit = self.semaphore.acquire().await;
776776

777777
self.with_verify_branch(project_id, |project_repository, _| {
@@ -787,7 +787,7 @@ impl ControllerInner {
787787
.project()
788788
.snapshot_branch_unapplied(snapshot_tree, result.as_ref())
789789
});
790-
result.map(|_| ())
790+
result.and_then(|b| b.reference_name())
791791
})
792792
}
793793

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ pub fn apply_branch(
282282
for branch in get_status_by_branch(project_repository, Some(&target_commit.id()))?
283283
.0
284284
.into_iter()
285+
.filter(|(branch, _)| branch.id != branch_id)
285286
.map(|(branch, _)| branch)
286287
{
287288
convert_to_real_branch(project_repository, branch.id, Default::default())?;
@@ -1445,7 +1446,7 @@ pub fn delete_branch(
14451446
branch_id: BranchId,
14461447
) -> Result<()> {
14471448
let vb_state = project_repository.project().virtual_branches();
1448-
let Some(branch) = dbg!(vb_state.try_branch(branch_id))? else {
1449+
let Some(branch) = vb_state.try_branch(branch_id)? else {
14491450
println!("I did nothing");
14501451
return Ok(());
14511452
};

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

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ async fn unapply_with_data() {
2727
assert!(!repository.path().join("file.txt").exists());
2828

2929
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap();
30-
assert_eq!(branches.len(), 1);
31-
assert!(!branches[0].active);
30+
assert_eq!(branches.len(), 0);
3231
}
3332

3433
#[tokio::test]
@@ -55,7 +54,7 @@ async fn conflicting() {
5554
.await
5655
.unwrap();
5756

58-
let branch_id = {
57+
let branch_reference = {
5958
// make a conflicting branch, and stash it
6059

6160
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
@@ -72,36 +71,28 @@ async fn conflicting() {
7271
controller
7372
.convert_to_real_branch(*project_id, branches[0].id, Default::default())
7473
.await
75-
.unwrap();
76-
77-
branches[0].id
74+
.unwrap()
7875
};
7976

8077
{
8178
// update base branch, causing conflict
82-
controller.update_base_branch(*project_id).await.unwrap();
79+
let unapplied_references = controller.update_base_branch(*project_id).await.unwrap();
8380

8481
assert_eq!(
8582
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
8683
"second"
8784
);
8885

89-
let branch = controller
90-
.list_virtual_branches(*project_id)
91-
.await
92-
.unwrap()
93-
.0
94-
.into_iter()
95-
.find(|branch| branch.id == branch_id)
96-
.unwrap();
97-
assert!(!branch.base_current);
98-
assert!(!branch.active);
86+
assert_eq!(unapplied_references.len(), 0);
9987
}
10088

101-
{
89+
let branch_id = {
10290
// apply branch, it should conflict
103-
controller
104-
.apply_virtual_branch(*project_id, branch_id)
91+
let branch_id = controller
92+
.create_virtual_branch_from_branch(
93+
*project_id,
94+
&git::Refname::from_str(branch_reference.as_str()).unwrap(),
95+
)
10596
.await
10697
.unwrap();
10798

@@ -118,10 +109,11 @@ async fn conflicting() {
118109
.into_iter()
119110
.find(|b| b.id == branch_id)
120111
.unwrap();
121-
assert!(branch.base_current);
122112
assert!(branch.conflicted);
123113
assert_eq!(branch.files[0].hunks[0].diff, "@@ -1 +1,5 @@\n-first\n\\ No newline at end of file\n+<<<<<<< ours\n+conflict\n+=======\n+second\n+>>>>>>> theirs\n");
124-
}
114+
115+
branch_id
116+
};
125117

126118
{
127119
controller
@@ -134,21 +126,13 @@ async fn conflicting() {
134126
"second"
135127
);
136128

137-
let branch = controller
129+
let branches = controller
138130
.list_virtual_branches(*project_id)
139131
.await
140132
.unwrap()
141-
.0
142-
.into_iter()
143-
.find(|b| b.id == branch_id)
144-
.unwrap();
145-
assert!(!branch.active);
146-
assert!(!branch.base_current);
147-
assert!(!branch.conflicted);
148-
assert_eq!(
149-
branch.files[0].hunks[0].diff,
150-
"@@ -1 +1 @@\n-first\n\\ No newline at end of file\n+conflict\n\\ No newline at end of file\n"
151-
);
133+
.0;
134+
135+
assert_eq!(branches.len(), 0);
152136
}
153137
}
154138

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -809,32 +809,38 @@ mod applied_branch {
809809
repository.fetch();
810810

811811
// The conflicted branch should be removed
812-
{
813-
controller.update_base_branch(*project_id).await.unwrap();
812+
let unapplied_branch = {
813+
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap();
814+
assert_eq!(unapplied_branches.len(), 1);
814815

815816
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap();
816-
dbg!(&branches);
817817
assert_eq!(branches.len(), 0);
818-
}
818+
819+
unapplied_branches[0].clone()
820+
};
819821

820822
{
821823
controller
822-
.apply_virtual_branch(*project_id, branch_id)
824+
.create_virtual_branch_from_branch(
825+
*project_id,
826+
&git::Refname::from_str(unapplied_branch.as_str()).unwrap(),
827+
)
823828
.await
824829
.unwrap();
825830

826831
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap();
827832
assert_eq!(branches.len(), 1);
828833
assert!(branches[0].active);
829834
assert!(branches[0].conflicted);
830-
assert!(branches[0].base_current);
835+
// assert!(branches[0].base_current);
831836
assert_eq!(branches[0].files.len(), 1);
832837
assert_eq!(branches[0].files[0].hunks.len(), 1);
833838
assert_eq!(
834839
branches[0].files[0].hunks[0].diff,
835840
"@@ -4,7 +4,11 @@\n 4\n 5\n 6\n-7\n+<<<<<<< ours\n+77\n+=======\n+17\n+>>>>>>> theirs\n 8\n 19\n 10\n"
836841
);
837-
assert_eq!(branches[0].commits.len(), 0);
842+
// We still have the WIP hunk
843+
assert_eq!(branches[0].commits.len(), 1);
838844
}
839845
}
840846

0 commit comments

Comments
 (0)