aqc_git_helpers/status.rs
1//! Change vocabulary: status matrix, one change, output filtering.
2
3/// Porcelain version this crate speaks.
4pub const PORCELAIN_VERSION: &str = "v1";
5
6/// One porcelain column's change kind (`X` index column / `Y` worktree column).
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ColumnChange {
9 /// `A`.
10 Added,
11 /// `M`.
12 Modified,
13 /// `D`.
14 Deleted,
15 /// `R`.
16 Renamed,
17 /// `C`.
18 Copied,
19 /// `T`.
20 TypeChanged,
21}
22
23/// How one path differs from HEAD/index.
24///
25/// Porcelain `XY` is a MATRIX: a path can be staged-modified AND
26/// unstaged-modified at once (`MM`), so tracked state carries both columns
27/// instead of collapsing them into one variant.
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum ChangeStatus {
30 /// A tracked path; at least one column is set.
31 Tracked {
32 /// The index (staged) column, `X`.
33 index: Option<ColumnChange>,
34 /// The worktree (unstaged) column, `Y`.
35 worktree: Option<ColumnChange>,
36 },
37 /// An unmerged path (`U` in either column, `AA`, `DD`). Dirty, fail-safe.
38 Conflicted,
39 /// `??`.
40 Untracked,
41 /// `!!` (listed only with `include_ignored`).
42 Ignored,
43}
44
45/// One changed path.
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct WorktreeChange {
48 /// Repo-relative, `/` separators, UTF-8.
49 pub path: String,
50 /// How it changed.
51 pub status: ChangeStatus,
52 /// Rename source path, when `status` is a rename.
53 pub old_path: Option<String>,
54}
55
56/// Output filtering.
57#[derive(Debug, Clone, Copy)]
58pub struct PorcelainOptions {
59 /// Keep `!!` entries.
60 pub include_ignored: bool,
61 /// Keep `??` entries.
62 pub include_untracked: bool,
63}
64
65impl Default for PorcelainOptions {
66 fn default() -> Self {
67 Self {
68 include_ignored: false,
69 include_untracked: true,
70 }
71 }
72}