1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, GwError>;
7
8#[derive(Error, Debug)]
10pub enum GwError {
11 #[error("Not in a git repository")]
12 NotAGitRepository,
13
14 #[error("Git command failed: {0}")]
15 GitCommandFailed(String),
16
17 #[error("Cannot switch to '{branch}' because it is checked out in another worktree{}", .path.as_deref().map(|p| format!(" ({p})")).unwrap_or_default())]
18 BranchCheckedOutElsewhere {
19 branch: String,
20 path: Option<String>,
21 },
22
23 #[error("Branch '{0}' already exists")]
24 BranchAlreadyExists(String),
25
26 #[error("Branch '{0}' does not exist")]
27 BranchNotFound(String),
28
29 #[error("Cannot delete protected branch: {0}")]
30 ProtectedBranch(String),
31
32 #[error("Uncommitted changes detected. Commit or stash them first.")]
33 UncommittedChanges,
34
35 #[error("Branch '{0}' has {1} unpushed commit(s)")]
36 UnpushedCommits(String, usize),
37
38 #[error("Already on home branch '{0}'. Specify a branch to delete.")]
39 AlreadyOnHomeBranch(String),
40
41 #[error("Branch name is required")]
42 BranchNameRequired,
43
44 #[error("IO error: {0}")]
45 Io(#[from] std::io::Error),
46
47 #[error("Cannot undo: no commits to undo (initial commit or empty history)")]
48 NothingToUndo,
49
50 #[error("Worktree pool is not initialized. Run `gw worktree pool warm <n>` first.")]
51 PoolNotInitialized,
52
53 #[error("No available worktrees in the pool. Run `gw worktree pool warm <n>` to add more.")]
54 PoolExhausted,
55
56 #[error("Pool has {0} acquired worktree(s). Release them first or use --force.")]
57 PoolHasAcquiredWorktrees(usize),
58
59 #[error("No acquired worktrees to release. Nothing to do.")]
60 PoolNoneAcquired,
61
62 #[error("Worktree '{0}' not found in pool")]
63 PoolWorktreeNotFound(String),
64
65 #[error("Worktree '{0}' is not acquired")]
66 PoolWorktreeNotAcquired(String),
67
68 #[error("Worktree '{name}' is not in a clean state to return to the pool: {reason}")]
69 PoolWorktreeDirty { name: String, reason: String },
70
71 #[error(
72 "No clean worktree available to acquire (all available worktrees are dirty). \
73 Inspect them, then run `gw worktree pool drain --force` and `gw worktree pool warm <n>`."
74 )]
75 PoolNoCleanWorktree,
76
77 #[error("Could not acquire pool lock within timeout")]
78 PoolLockTimeout,
79
80 #[error("{0}")]
81 Other(String),
82}