ok/jj
1
0
Fork 0
forked from mirrors/jj

repo: add a specific error type for MutableRepo::check_out()

This commit is contained in:
Martin von Zweigbergk 2023-01-22 21:38:06 -08:00 committed by Martin von Zweigbergk
parent eb7de6dd3c
commit 63aa484046
3 changed files with 25 additions and 8 deletions

View file

@ -746,7 +746,7 @@ impl MutableRepo {
workspace_id: WorkspaceId,
settings: &UserSettings,
commit: &Commit,
) -> BackendResult<Commit> {
) -> Result<Commit, CheckOutCommitError> {
let wc_commit = self
.new_commit(
settings,
@ -754,7 +754,7 @@ impl MutableRepo {
commit.tree_id().clone(),
)
.write()?;
self.edit(workspace_id, &wc_commit).unwrap();
self.edit(workspace_id, &wc_commit)?;
Ok(wc_commit)
}
@ -1101,7 +1101,7 @@ impl MutableRepo {
}
/// Error from attempts to check out the root commit for editing
#[derive(Debug, Copy, Clone, Error)]
#[derive(Debug, Error)]
#[error("Cannot rewrite the root commit")]
pub struct RewriteRootCommit;
@ -1112,6 +1112,15 @@ pub enum EditCommitError {
RewriteRootCommit,
}
/// Error from attempts to check out a commit
#[derive(Debug, Error)]
pub enum CheckOutCommitError {
#[error("Failed to create new working-copy commit: {0}")]
CreateCommit(#[from] BackendError),
#[error("Failed to edit commit: {0}")]
EditCommit(#[from] EditCommitError),
}
#[derive(Debug, Error)]
#[error("Cannot access {path}")]
pub struct PathError {

View file

@ -19,13 +19,15 @@ use std::sync::Arc;
use thiserror::Error;
use crate::backend::{Backend, BackendError};
use crate::backend::Backend;
use crate::git_backend::GitBackend;
use crate::local_backend::LocalBackend;
use crate::op_heads_store::OpHeadsStore;
use crate::op_store::{self, OpStore, OperationMetadata, WorkspaceId};
use crate::operation::Operation;
use crate::repo::{IoResultExt, PathError, ReadonlyRepo, RepoLoader, StoreFactories};
use crate::repo::{
CheckOutCommitError, IoResultExt, PathError, ReadonlyRepo, RepoLoader, StoreFactories,
};
use crate::settings::UserSettings;
use crate::working_copy::WorkingCopy;
@ -36,7 +38,7 @@ pub enum WorkspaceInitError {
#[error("Repo path could not be interpreted as Unicode text")]
NonUnicodePath,
#[error(transparent)]
BackendError(#[from] BackendError),
CheckOutCommit(#[from] CheckOutCommitError),
#[error(transparent)]
Path(#[from] PathError),
}

View file

@ -37,8 +37,8 @@ use jujutsu_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, WorkspaceId};
use jujutsu_lib::operation::Operation;
use jujutsu_lib::repo::{
EditCommitError, MutableRepo, ReadonlyRepo, RepoLoader, RepoRef, RewriteRootCommit,
StoreFactories,
CheckOutCommitError, EditCommitError, MutableRepo, ReadonlyRepo, RepoLoader, RepoRef,
RewriteRootCommit, StoreFactories,
};
use jujutsu_lib::repo_path::{FsPathParseError, RepoPath};
use jujutsu_lib::revset::{
@ -124,6 +124,12 @@ impl From<EditCommitError> for CommandError {
}
}
impl From<CheckOutCommitError> for CommandError {
fn from(err: CheckOutCommitError) -> Self {
CommandError::InternalError(format!("Failed to check out a commit: {err}"))
}
}
impl From<BackendError> for CommandError {
fn from(err: BackendError) -> Self {
user_error(format!("Unexpected error from backend: {err}"))