mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 07:14:38 +00:00
cli: in jj chmod
, check if all sides are files first
This is mostly to allow us to simplify the code that comes after in the next commit.
This commit is contained in:
parent
a80259c7d3
commit
725f79cd65
1 changed files with 10 additions and 9 deletions
|
@ -2663,13 +2663,18 @@ fn cmd_chmod(ui: &mut Ui, command: &CommandHelper, args: &ChmodArgs) -> Result<(
|
||||||
},
|
},
|
||||||
Some(TreeValue::Conflict(id)) => {
|
Some(TreeValue::Conflict(id)) => {
|
||||||
let conflict = tree.store().read_conflict(&repo_path, &id)?;
|
let conflict = tree.store().read_conflict(&repo_path, &id)?;
|
||||||
let (new_removes, _) = chmod_conflict_sides(conflict.removes(), executable_bit);
|
let all_files = conflict
|
||||||
let (new_adds, all_files) = chmod_conflict_sides(conflict.adds(), executable_bit);
|
.adds()
|
||||||
|
.iter()
|
||||||
|
.flatten()
|
||||||
|
.all(|tree_value| matches!(tree_value, TreeValue::File { .. }));
|
||||||
if !all_files {
|
if !all_files {
|
||||||
return Err(user_error_with_path(
|
return Err(user_error_with_path(
|
||||||
"Some of the sides of the conflict are not files",
|
"Some of the sides of the conflict are not files",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
let new_removes = chmod_conflict_sides(conflict.removes(), executable_bit);
|
||||||
|
let new_adds = chmod_conflict_sides(conflict.adds(), executable_bit);
|
||||||
let new_conflict_id =
|
let new_conflict_id =
|
||||||
store.write_conflict(&repo_path, &Merge::new(new_removes, new_adds))?;
|
store.write_conflict(&repo_path, &Merge::new(new_removes, new_adds))?;
|
||||||
TreeValue::Conflict(new_conflict_id)
|
TreeValue::Conflict(new_conflict_id)
|
||||||
|
@ -2689,8 +2694,7 @@ fn cmd_chmod(ui: &mut Ui, command: &CommandHelper, args: &ChmodArgs) -> Result<(
|
||||||
fn chmod_conflict_sides(
|
fn chmod_conflict_sides(
|
||||||
sides: &[Option<TreeValue>],
|
sides: &[Option<TreeValue>],
|
||||||
executable_bit: bool,
|
executable_bit: bool,
|
||||||
) -> (Vec<Option<TreeValue>>, bool) {
|
) -> Vec<Option<TreeValue>> {
|
||||||
let mut all_files = true;
|
|
||||||
let result = sides
|
let result = sides
|
||||||
.iter()
|
.iter()
|
||||||
.map(|side| {
|
.map(|side| {
|
||||||
|
@ -2700,14 +2704,11 @@ fn chmod_conflict_sides(
|
||||||
executable: executable_bit,
|
executable: executable_bit,
|
||||||
},
|
},
|
||||||
TreeValue::Conflict(_) => panic!("Conflict sides must not themselves be conflicts"),
|
TreeValue::Conflict(_) => panic!("Conflict sides must not themselves be conflicts"),
|
||||||
value => {
|
value => value.clone(),
|
||||||
all_files = false;
|
|
||||||
value.clone()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
(result, all_files)
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
|
|
Loading…
Reference in a new issue