Skip to content

Commit f6345a6

Browse files
authored
Improve when the commit suggestions would show (#26313)
Release Notes: - Git Beta: Fixed a few bugs where the suggested commit text wouldn't show in certain cases, or would update slowly.
1 parent e70d0ed commit f6345a6

File tree

4 files changed

+180
-89
lines changed

4 files changed

+180
-89
lines changed

crates/git/src/status.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,39 @@ impl From<TrackedStatus> for FileStatus {
5454
}
5555
}
5656

57+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
58+
pub enum StageStatus {
59+
Staged,
60+
Unstaged,
61+
PartiallyStaged,
62+
}
63+
64+
impl StageStatus {
65+
pub fn is_fully_staged(&self) -> bool {
66+
matches!(self, StageStatus::Staged)
67+
}
68+
69+
pub fn is_fully_unstaged(&self) -> bool {
70+
matches!(self, StageStatus::Unstaged)
71+
}
72+
73+
pub fn has_staged(&self) -> bool {
74+
matches!(self, StageStatus::Staged | StageStatus::PartiallyStaged)
75+
}
76+
77+
pub fn has_unstaged(&self) -> bool {
78+
matches!(self, StageStatus::Unstaged | StageStatus::PartiallyStaged)
79+
}
80+
81+
pub fn as_bool(self) -> Option<bool> {
82+
match self {
83+
StageStatus::Staged => Some(true),
84+
StageStatus::Unstaged => Some(false),
85+
StageStatus::PartiallyStaged => None,
86+
}
87+
}
88+
}
89+
5790
impl FileStatus {
5891
pub const fn worktree(worktree_status: StatusCode) -> Self {
5992
FileStatus::Tracked(TrackedStatus {
@@ -106,15 +139,15 @@ impl FileStatus {
106139
Ok(status)
107140
}
108141

109-
pub fn is_staged(self) -> Option<bool> {
142+
pub fn staging(self) -> StageStatus {
110143
match self {
111144
FileStatus::Untracked | FileStatus::Ignored | FileStatus::Unmerged { .. } => {
112-
Some(false)
145+
StageStatus::Unstaged
113146
}
114147
FileStatus::Tracked(tracked) => match (tracked.index_status, tracked.worktree_status) {
115-
(StatusCode::Unmodified, _) => Some(false),
116-
(_, StatusCode::Unmodified) => Some(true),
117-
_ => None,
148+
(StatusCode::Unmodified, _) => StageStatus::Unstaged,
149+
(_, StatusCode::Unmodified) => StageStatus::Staged,
150+
_ => StageStatus::PartiallyStaged,
118151
},
119152
}
120153
}

0 commit comments

Comments
 (0)