Skip to content

Commit 71b0cea

Browse files
committed
feat: Add support for index application in merge results via merge::tree::Outcome::index_changed_after_applying_conflicts()
1 parent 3ee8b62 commit 71b0cea

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crate-status.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ Check out the [performance discussion][gix-diff-performance] as well.
353353
* [x] **tree**-diff-heuristics match Git for its test-cases
354354
- [x] a way to generate an index with stages, mostly conforming with Git.
355355
- [ ] submodule merges (*right now they count as conflicts if they differ*)
356+
- [ ] assure sparse indices are handled correctly during application - right now we refuse.
356357
* [x] **commits** - with handling of multiple merge bases by recursive merge-base merge
357358
* [x] API documentation
358359
* [ ] Examples

gix/src/merge.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ pub mod tree {
133133
pub fn has_unresolved_conflicts(&self, how: TreatAsUnresolved) -> bool {
134134
self.conflicts.iter().any(|c| c.is_unresolved(how))
135135
}
136+
137+
/// Returns `true` if `index` changed as we applied conflicting stages to it, using `how` to determine if a
138+
/// conflict should be considered unresolved.
139+
/// It's important that `index` is at the state of [`Self::tree`].
140+
///
141+
/// Note that in practice, whenever there is a single [conflict](Conflict), this function will return `true`.
142+
///
143+
/// ### Important
144+
///
145+
/// Also, the unconflicted stage of such entries will be removed merely by setting a flag, so the
146+
/// in-memory entry is still present.
147+
/// One can prune `index` [in-memory](gix_index::State::remove_entries()) or write it to disk, which will
148+
/// cause entries marked for removal not to be persisted.
149+
pub fn index_changed_after_applying_conflicts(
150+
&self,
151+
index: &mut gix_index::State,
152+
how: TreatAsUnresolved,
153+
) -> bool {
154+
gix_merge::tree::apply_index_entries(&self.conflicts, how, index)
155+
}
136156
}
137157

138158
/// A way to configure [`Repository::merge_trees()`](crate::Repository::merge_trees()).

0 commit comments

Comments
 (0)