1#[derive(Debug, thiserror::Error)]
2#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
3pub enum GitError {
4 #[error("Repository not found at path: {path}")]
5 RepoNotFound { path: String },
6
7 #[error("Not a git repository: {path}")]
8 NotARepo { path: String },
9
10 #[error("Revision not found: {rev}")]
11 RevNotFound { rev: String },
12
13 #[error("Config key not found: {key}")]
14 ConfigNotFound { key: String },
15
16 #[error("Authentication failed for remote: {url}")]
17 AuthenticationFailed { url: String },
18
19 #[error("Push rejected: {reason}")]
20 PushRejected { reason: String },
21
22 #[error("Remote not found: {name}")]
23 RemoteNotFound { name: String },
24
25 #[error("Merge conflict: {message}")]
26 MergeConflict { message: String },
27
28 #[error("Detached HEAD: cannot rewrite without a branch")]
29 DetachedHead,
30
31 #[error("Working tree has uncommitted changes")]
32 WorkingTreeDirty,
33
34 #[error("A git operation is already in progress")]
35 OperationInProgress,
36
37 #[error("Merge commit cannot be rewritten: {hash}")]
38 MergeCommitUnsupported { hash: String },
39
40 #[error("Cherry-pick conflict at commit {hash}: {details}")]
41 CherryPickConflict { hash: String, details: String },
42
43 #[error("Cherry-pick produced no changes — commit {hash} is already applied")]
44 CherryPickEmpty { hash: String },
45
46 #[error("Commit not found in current branch history: {hash}")]
47 CommitNotInChain { hash: String },
48
49 #[error("Stash pop failed after rewrite: {message}")]
50 StashPopFailed { message: String },
51
52 #[error("{message}")]
53 Internal { message: String },
54}
55
56impl GitError {
57 pub fn internal(e: impl std::fmt::Display) -> Self {
58 Self::Internal {
59 message: e.to_string(),
60 }
61 }
62}
63
64impl From<gix::open::Error> for GitError {
65 fn from(e: gix::open::Error) -> Self {
66 Self::Internal {
67 message: e.to_string(),
68 }
69 }
70}
71
72impl From<std::io::Error> for GitError {
73 fn from(e: std::io::Error) -> Self {
74 Self::Internal {
75 message: e.to_string(),
76 }
77 }
78}