From 3280d75ff479fba08c581b5843d3ba5e1e35f4a2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 26 Dec 2020 10:34:58 -0800 Subject: [PATCH] diff_edit: mark "before" directory readonly to clarify to user Changes to the "before" side of the diff will have no effect, so let's clarify that by marking it readonly. At least Meld checks the permissions and shows in the UI that the left side is readonly. --- src/diff_edit.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/diff_edit.rs b/src/diff_edit.rs index 77e9f6a61..2b284e657 100644 --- a/src/diff_edit.rs +++ b/src/diff_edit.rs @@ -19,7 +19,7 @@ use jj_lib::tree::Tree; use jj_lib::tree_builder::TreeBuilder; use jj_lib::trees::merge_trees; use jj_lib::working_copy::{CheckoutError, TreeState}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Arc; use tempfile::tempdir; @@ -80,6 +80,17 @@ fn check_out( Ok(tree_state) } +fn set_readonly_recursively(path: &Path) { + if path.is_dir() { + for entry in path.read_dir().unwrap() { + set_readonly_recursively(&entry.unwrap().path()); + } + } + let mut perms = std::fs::metadata(path).unwrap().permissions(); + perms.set_readonly(true); + std::fs::set_permissions(path, perms).unwrap(); +} + pub fn edit_diff(left_tree: &Tree, right_tree: &Tree) -> Result { // First create partial Trees of only the subset of the left and right trees // that affect files changed between them. @@ -112,7 +123,7 @@ pub fn edit_diff(left_tree: &Tree, right_tree: &Tree) -> Result