mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-23 20:54:50 +03:00
move error marker out of virtual_branches mod
It's useful outside of it
This commit is contained in:
parent
f67744eea1
commit
b72f9c2199
@ -231,3 +231,30 @@ impl AnyhowContextExt for anyhow::Error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
|
||||||
|
/// that a certain even happened.
|
||||||
|
///
|
||||||
|
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
|
||||||
|
/// to signify its marker status.
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Marker {
|
||||||
|
/// Invalid state was detected, making the repository invalid for operation.
|
||||||
|
VerificationFailure,
|
||||||
|
/// An indicator for a conflict in the project.
|
||||||
|
///
|
||||||
|
/// See usages for details on what these conflicts can be.
|
||||||
|
ProjectConflict,
|
||||||
|
/// An indicator that a branch conflicted during applying to the workspace.
|
||||||
|
BranchConflict,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Marker {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Marker::VerificationFailure => f.write_str("<verification-failed>"),
|
||||||
|
Marker::ProjectConflict => f.write_str("<project-conflict>"),
|
||||||
|
Marker::BranchConflict => f.write_str("<branch-conflict>"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||||||
ssh, users,
|
ssh, users,
|
||||||
virtual_branches::{Branch, BranchId},
|
virtual_branches::{Branch, BranchId},
|
||||||
};
|
};
|
||||||
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
|
use crate::{error::Marker, git::RepositoryExt};
|
||||||
|
|
||||||
pub struct Repository {
|
pub struct Repository {
|
||||||
git_repository: git2::Repository,
|
git_repository: git2::Repository,
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use crate::{
|
use crate::{error::Marker, git::CommitExt, git::RepositoryExt, project_repository};
|
||||||
git::CommitExt, git::RepositoryExt, project_repository, virtual_branches::errors::Marker,
|
|
||||||
};
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use super::{
|
|||||||
},
|
},
|
||||||
target, BranchId, RemoteCommit, VirtualBranchHunk, VirtualBranchesHandle,
|
target, BranchId, RemoteCommit, VirtualBranchHunk, VirtualBranchesHandle,
|
||||||
};
|
};
|
||||||
use crate::{git::RepositoryExt, rebase::cherry_rebase, virtual_branches::errors::Marker};
|
use crate::{error::Marker, git::RepositoryExt, rebase::cherry_rebase};
|
||||||
use crate::{
|
use crate::{
|
||||||
git::{self, diff},
|
git::{self, diff},
|
||||||
project_repository::{self, LogUntil},
|
project_repository::{self, LogUntil},
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
|
|
||||||
/// that a certain even happened.
|
|
||||||
///
|
|
||||||
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
|
|
||||||
/// to signify its marker status.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
||||||
pub enum Marker {
|
|
||||||
/// Invalid state was detected, making the repository invalid for operation.
|
|
||||||
VerificationFailure,
|
|
||||||
/// An indicator for a conflict in the project.
|
|
||||||
///
|
|
||||||
/// See usages for details on what these conflicts can be.
|
|
||||||
ProjectConflict,
|
|
||||||
/// An indicator that a branch conflicted during applying to the workspace.
|
|
||||||
BranchConflict,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for Marker {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Marker::VerificationFailure => f.write_str("<verification-failed>"),
|
|
||||||
Marker::ProjectConflict => f.write_str("<project-conflict>"),
|
|
||||||
Marker::BranchConflict => f.write_str("<branch-conflict>"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,8 +5,8 @@ use bstr::ByteSlice;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use super::VirtualBranchesHandle;
|
use super::VirtualBranchesHandle;
|
||||||
|
use crate::error::Marker;
|
||||||
use crate::git::RepositoryExt;
|
use crate::git::RepositoryExt;
|
||||||
use crate::virtual_branches::errors::Marker;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
git::{self, CommitExt},
|
git::{self, CommitExt},
|
||||||
project_repository::{self, conflicts, LogUntil},
|
project_repository::{self, conflicts, LogUntil},
|
||||||
|
@ -2,8 +2,6 @@ pub mod branch;
|
|||||||
pub use branch::{Branch, BranchId};
|
pub use branch::{Branch, BranchId};
|
||||||
pub mod target;
|
pub mod target;
|
||||||
|
|
||||||
pub mod errors;
|
|
||||||
|
|
||||||
mod files;
|
mod files;
|
||||||
pub use files::*;
|
pub use files::*;
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ use super::{
|
|||||||
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
|
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
|
||||||
};
|
};
|
||||||
use crate::error::Code;
|
use crate::error::Code;
|
||||||
|
use crate::error::Marker;
|
||||||
use crate::git::diff::GitHunk;
|
use crate::git::diff::GitHunk;
|
||||||
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
|
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
|
||||||
use crate::git::{CommitExt, RepositoryExt};
|
use crate::git::{CommitExt, RepositoryExt};
|
||||||
use crate::rebase::{cherry_rebase, cherry_rebase_group};
|
use crate::rebase::{cherry_rebase, cherry_rebase_group};
|
||||||
use crate::time::now_since_unix_epoch_ms;
|
use crate::time::now_since_unix_epoch_ms;
|
||||||
use crate::virtual_branches::branch::HunkHash;
|
use crate::virtual_branches::branch::HunkHash;
|
||||||
use crate::virtual_branches::errors::Marker;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dedup::{dedup, dedup_fmt},
|
dedup::{dedup, dedup_fmt},
|
||||||
git::{
|
git::{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{fs, path, str::FromStr};
|
use std::{fs, path, str::FromStr};
|
||||||
|
|
||||||
use gitbutler_core::virtual_branches::errors::Marker;
|
use gitbutler_core::error::Marker;
|
||||||
use gitbutler_core::{
|
use gitbutler_core::{
|
||||||
git,
|
git,
|
||||||
projects::{self, Project, ProjectId},
|
projects::{self, Project, ProjectId},
|
||||||
|
@ -2,6 +2,7 @@ use std::path::PathBuf;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use gitbutler_core::error::Marker;
|
||||||
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
|
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
|
||||||
use gitbutler_core::projects::ProjectId;
|
use gitbutler_core::projects::ProjectId;
|
||||||
use gitbutler_core::synchronize::sync_with_gitbutler;
|
use gitbutler_core::synchronize::sync_with_gitbutler;
|
||||||
@ -101,8 +102,8 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
Err(err)
|
Err(err)
|
||||||
if matches!(
|
if matches!(
|
||||||
err.downcast_ref::<virtual_branches::errors::Marker>(),
|
err.downcast_ref::<Marker>(),
|
||||||
Some(virtual_branches::errors::Marker::VerificationFailure)
|
Some(Marker::VerificationFailure)
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user