cli: Display better errors in `patch ready`

Instead of doing nothing and going to sync no change, we should display
some error to the users that we haven't been able to apply the changes.
This commit is contained in:
Sebastian Martinez 2024-03-15 12:41:32 +01:00 committed by cloudhead
parent 0a78b9cc5b
commit d38846baae
No known key found for this signature in database
2 changed files with 12 additions and 5 deletions

View File

@ -743,7 +743,14 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
} }
Operation::Ready { ref patch_id, undo } => { Operation::Ready { ref patch_id, undo } => {
let patch_id = patch_id.resolve::<PatchId>(&repository.backend)?; let patch_id = patch_id.resolve::<PatchId>(&repository.backend)?;
ready::run(&patch_id, undo, &profile, &repository)?;
if !ready::run(&patch_id, undo, &profile, &repository)? {
if undo {
anyhow::bail!("the patch must be open to be put in draft state");
} else {
anyhow::bail!("this patch must be in draft state to be put in open state");
}
}
} }
Operation::Delete { patch_id } => { Operation::Delete { patch_id } => {
let patch_id = patch_id.resolve::<PatchId>(&repository.backend)?; let patch_id = patch_id.resolve::<PatchId>(&repository.backend)?;

View File

@ -8,7 +8,7 @@ pub fn run(
undo: bool, undo: bool,
profile: &Profile, profile: &Profile,
repository: &Repository, repository: &Repository,
) -> anyhow::Result<()> { ) -> anyhow::Result<bool> {
let signer = term::signer(profile)?; let signer = term::signer(profile)?;
let mut patches = profile.patches_mut(repository)?; let mut patches = profile.patches_mut(repository)?;
let Ok(mut patch) = patches.get_mut(patch_id) else { let Ok(mut patch) = patches.get_mut(patch_id) else {
@ -16,9 +16,9 @@ pub fn run(
}; };
if undo { if undo {
patch.unready(&signer)?; patch.unready(&signer)
} else { } else {
patch.ready(&signer)?; patch.ready(&signer)
} }
Ok(()) .map_err(anyhow::Error::from)
} }