1use std::path::PathBuf;
7
8use crate::GitRequestId;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum GitChangeKind {
12 Modified,
13 Added,
14 Deleted,
15 Renamed { from: PathBuf },
16 Untracked,
17 Conflicted,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct GitFileStatus {
22 pub path: PathBuf,
24 pub index: Option<GitChangeKind>,
25 pub worktree: Option<GitChangeKind>,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct GitBranchStatus {
30 pub oid: Option<String>,
31 pub head: Option<String>,
32 pub upstream: Option<String>,
33 pub ahead: usize,
34 pub behind: usize,
35 pub detached: bool,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq)]
39pub struct GitBranch {
40 pub name: String,
41 pub current: bool,
42}
43
44#[derive(Debug, Clone, PartialEq, Eq, Default)]
45pub struct GitContextDiff {
46 pub index: String,
47 pub worktree: String,
48 pub index_truncated: bool,
49 pub worktree_truncated: bool,
50}
51
52#[derive(Debug, Clone, PartialEq, Eq)]
53pub struct GitRepositorySnapshot {
54 pub repository_root: PathBuf,
55 pub workspace_root: PathBuf,
56 pub branch: GitBranchStatus,
57 pub files: Vec<GitFileStatus>,
58 pub context_diff: GitContextDiff,
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62pub enum GitDiffTarget {
63 Worktree,
64 Index,
65}
66
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct GitFileDiff {
69 pub path: PathBuf,
70 pub target: GitDiffTarget,
71 pub text: String,
72 pub truncated: bool,
73}
74
75#[derive(Debug, Clone, PartialEq, Eq)]
76pub enum GitOperation {
77 Stage { path: PathBuf },
78 Unstage { path: PathBuf },
79 Commit { message: String },
80 Checkout { branch: String },
81 Fetch,
82 Pull,
83 Push,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
87pub enum GitRequest {
88 Refresh { id: GitRequestId, root: PathBuf },
89 Diff { id: GitRequestId, root: PathBuf, path: PathBuf, target: GitDiffTarget },
90 Branches { id: GitRequestId, root: PathBuf },
91 Execute { id: GitRequestId, root: PathBuf, operation: GitOperation },
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq)]
95pub enum GitFailureKind {
96 NotRepository,
97 Unavailable,
98 InvalidOutput,
99 Command,
100}
101
102#[derive(Debug, Clone, PartialEq, Eq)]
103pub struct GitFailure {
104 pub kind: GitFailureKind,
105 pub message: String,
106}
107
108pub type GitResult<T> = Result<T, GitFailure>;
109
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub enum GitEvent {
112 Started {
113 id: GitRequestId,
114 },
115 SnapshotLoaded {
116 id: GitRequestId,
117 snapshot: GitRepositorySnapshot,
118 },
119 DiffLoaded {
120 id: GitRequestId,
121 diff: GitFileDiff,
122 },
123 BranchesLoaded {
124 id: GitRequestId,
125 branches: Vec<GitBranch>,
126 },
127 OperationFinished {
128 id: GitRequestId,
129 operation: GitOperation,
130 message: String,
131 snapshot: GitRepositorySnapshot,
132 },
133 Failed {
134 id: GitRequestId,
135 operation_applied: bool,
136 failure: GitFailure,
137 },
138}