Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix a bug that interfered with sorting of conflicted paths in the git panel (#29534)

Cole Miller7587340fb14e
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index aaf66e8ea98..debb1c643b0 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -2692,6 +2692,7 @@ impl MergeDetails {
status: &SumTree<StatusEntry>,
prev_snapshot: &RepositorySnapshot,
) -> Result<(MergeDetails, bool)> {
+ log::debug!("load merge details");
let message = backend.merge_message().await;
let heads = backend
.revparse_batch(vec![
@@ -2709,12 +2710,33 @@ impl MergeDetails {
.collect::<Vec<_>>();
let merge_heads_changed = heads != prev_snapshot.merge.heads;
let conflicted_paths = if merge_heads_changed {
- TreeSet::from_ordered_entries(
+ let current_conflicted_paths = TreeSet::from_ordered_entries(
status
.iter()
.filter(|entry| entry.status.is_conflicted())
.map(|entry| entry.repo_path.clone()),
- )
+ );
+
+ // It can happen that we run a scan while a lengthy merge is in progress
+ // that will eventually result in conflicts, but before those conflicts
+ // are reported by `git status`. Since for the moment we only care about
+ // the merge heads state for the purposes of tracking conflicts, don't update
+ // this state until we see some conflicts.
+ if heads.iter().any(Option::is_some)
+ && !prev_snapshot.merge.heads.iter().any(Option::is_some)
+ && current_conflicted_paths.is_empty()
+ {
+ log::debug!("not updating merge heads because no conflicts found");
+ return Ok((
+ MergeDetails {
+ message: message.map(SharedString::from),
+ ..prev_snapshot.merge.clone()
+ },
+ false,
+ ));
+ }
+
+ current_conflicted_paths
} else {
prev_snapshot.merge.conflicted_paths.clone()
};
@@ -3998,6 +4020,8 @@ impl Repository {
Some(GitJobKey::ReloadGitState),
None,
|state, mut cx| async move {
+ log::debug!("run scheduled git status scan");
+
let Some(this) = this.upgrade() else {
return Ok(());
};
@@ -4535,6 +4559,7 @@ async fn compute_snapshot(
);
let (merge_details, merge_heads_changed) =
MergeDetails::load(&backend, &statuses_by_path, &prev_snapshot).await?;
+ log::debug!("new merge details (changed={merge_heads_changed:?}): {merge_details:?}");
if merge_heads_changed
|| branch != prev_snapshot.branch