@@ -54,6 +54,39 @@ impl From<TrackedStatus> for FileStatus {
54
54
}
55
55
}
56
56
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
+
57
90
impl FileStatus {
58
91
pub const fn worktree ( worktree_status : StatusCode ) -> Self {
59
92
FileStatus :: Tracked ( TrackedStatus {
@@ -106,15 +139,15 @@ impl FileStatus {
106
139
Ok ( status)
107
140
}
108
141
109
- pub fn is_staged ( self ) -> Option < bool > {
142
+ pub fn staging ( self ) -> StageStatus {
110
143
match self {
111
144
FileStatus :: Untracked | FileStatus :: Ignored | FileStatus :: Unmerged { .. } => {
112
- Some ( false )
145
+ StageStatus :: Unstaged
113
146
}
114
147
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 ,
118
151
} ,
119
152
}
120
153
}
0 commit comments