From b227dde7877c4d5c86df872312211ed6da7bcaf0 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 20 May 2024 23:59:24 -0700 Subject: [PATCH] conflicts: indicate executable conflict in git-format diff --- cli/src/diff_util.rs | 13 +++++++++++-- cli/src/merge_tools/builtin.rs | 6 +++++- lib/src/conflicts.rs | 7 +++++++ lib/src/local_working_copy.rs | 13 +++++-------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 6b88f6b6e..264bffffa 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -467,7 +467,11 @@ fn diff_content(path: &RepoPath, value: MaterializedTreeValue) -> io::Result Ok(FileContent { + MaterializedTreeValue::Conflict { + id: _, + contents, + executable: _, + } => Ok(FileContent { is_binary: false, contents, }), @@ -660,8 +664,13 @@ fn git_diff_part(path: &RepoPath, value: MaterializedTreeValue) -> io::Result { - mode = "100644".to_string(); + mode = if executable { + "100755".to_string() + } else { + "100644".to_string() + }; hash = "0000000000".to_string(); contents = conflict_data } diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index 217d95aef..fbbf2888b 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -184,7 +184,11 @@ fn read_file_contents( item: "git submodule", id: id.hex(), }), - MaterializedTreeValue::Conflict { id: _, contents } => { + MaterializedTreeValue::Conflict { + id: _, + contents, + executable: _, + } => { // TODO: Render the ID somehow? let contents = buf_to_file_contents(None, contents); Ok(FileInfo { diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 9c5dd469a..8163d0d09 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -139,6 +139,7 @@ pub enum MaterializedTreeValue { Conflict { id: MergedTreeValue, contents: Vec, + executable: bool, }, GitSubmodule(CommitId), Tree(TreeId), @@ -185,9 +186,15 @@ pub async fn materialize_tree_value( materialize(&conflict, store, path, &mut contents) .await .expect("Failed to materialize conflict to in-memory buffer"); + let executable = if let Some(merge) = conflict.to_executable_merge() { + merge.resolve_trivial().copied().unwrap_or_default() + } else { + false + }; Ok(MaterializedTreeValue::Conflict { id: conflict, contents, + executable, }) } } diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index b72a9168b..d585c6041 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1398,14 +1398,11 @@ impl TreeState { MaterializedTreeValue::Tree(_) => { panic!("unexpected tree entry in diff at {path:?}"); } - MaterializedTreeValue::Conflict { id, contents } => { - let executable = if let Some(merge) = id.to_executable_merge() { - merge.resolve_trivial().copied().unwrap_or_default() - } else { - false - }; - self.write_conflict(&disk_path, contents, executable)? - } + MaterializedTreeValue::Conflict { + id: _, + contents, + executable, + } => self.write_conflict(&disk_path, contents, executable)?, }; changed_file_states.push((path, file_state)); }