@@ -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+
5790impl 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