Skip to content

Commit 3aa9f7b

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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)