@@ -8,6 +8,7 @@ use gix::{
8
8
sec:: { self , trust:: DefaultForLevel } ,
9
9
} ;
10
10
use log:: debug;
11
+ use num_enum:: IntoPrimitive ;
11
12
use std:: borrow:: Cow ;
12
13
use std:: env;
13
14
use std:: path:: Path ;
@@ -55,14 +56,24 @@ fn main() {
55
56
56
57
println ! ( "{progress_status}" ) ;
57
58
58
- let status = get_status ( & repo) ;
59
+ let status = get_status ( & repo) . into ( ) ;
59
60
60
61
exit ( status)
61
62
}
62
63
63
- fn get_status ( repo : & Repo ) -> i32 {
64
+ #[ derive( Debug , IntoPrimitive ) ]
65
+ #[ repr( i32 ) ]
66
+ enum Status {
67
+ Unchange = 5 ,
68
+ Change = 6 ,
69
+ Untracked = 7 ,
70
+ HasError = 8 ,
71
+ Disable = 9 ,
72
+ }
73
+
74
+ fn get_status ( repo : & Repo ) -> Status {
64
75
if env:: var ( "BASH_DISABLE_GIT_FILE_TRACKING" ) . is_ok ( ) {
65
- return 9 ;
76
+ return Status :: Disable ;
66
77
}
67
78
68
79
let repo = repo. repo . to_thread_local ( ) ;
@@ -75,7 +86,7 @@ fn get_status(repo: &Repo) -> i32 {
75
86
. status ( progress:: Discard )
76
87
. inspect_err ( |e| debug ! ( "{e}" ) )
77
88
else {
78
- return 8 ;
89
+ return Status :: HasError ;
79
90
} ;
80
91
81
92
let status = status. index_worktree_submodules ( Submodule :: AsConfigured { check_dirty : true } ) ;
@@ -104,14 +115,16 @@ fn get_status(repo: &Repo) -> i32 {
104
115
// This will start the status machinery, collecting status items in the background.
105
116
// Thus, we can do some work in this thread without blocking, before starting to count status items.
106
117
let Ok ( status) = status. into_iter ( None ) . inspect_err ( |e| debug ! ( "{e}" ) ) else {
107
- return 8 ;
118
+ return Status :: HasError ;
108
119
} ;
109
120
121
+ let mut is_untracked = false ;
122
+
110
123
for change in status. filter_map ( Result :: ok) {
111
124
use gix:: status;
112
125
match & change {
113
126
status:: Item :: TreeIndex ( _) => {
114
- return 6 ;
127
+ return Status :: Change ;
115
128
}
116
129
status:: Item :: IndexWorktree ( change) => {
117
130
use gix:: status:: index_worktree:: Item ;
@@ -121,13 +134,13 @@ fn get_status(repo: &Repo) -> i32 {
121
134
status : EntryStatus :: Conflict ( _) ,
122
135
..
123
136
} => {
124
- return 6 ;
137
+ return Status :: Change ;
125
138
}
126
139
Item :: Modification {
127
140
status : EntryStatus :: Change ( Change :: Removed ) ,
128
141
..
129
142
} => {
130
- return 6 ;
143
+ return Status :: Change ;
131
144
}
132
145
Item :: Modification {
133
146
status :
@@ -137,13 +150,13 @@ fn get_status(repo: &Repo) -> i32 {
137
150
) ,
138
151
..
139
152
} => {
140
- return 6 ;
153
+ return Status :: Change ;
141
154
}
142
155
Item :: Modification {
143
156
status : EntryStatus :: Change ( Change :: Type ) ,
144
157
..
145
158
} => {
146
- return 6 ;
159
+ return Status :: Change ;
147
160
}
148
161
Item :: DirectoryContents {
149
162
entry :
@@ -153,7 +166,7 @@ fn get_status(repo: &Repo) -> i32 {
153
166
} ,
154
167
..
155
168
} => {
156
- return 7 ;
169
+ is_untracked = true ;
157
170
}
158
171
Item :: Rewrite { .. } => {
159
172
unreachable ! ( "this kind of rename tracking isn't enabled by default and specific to gitoxide" )
@@ -164,16 +177,20 @@ fn get_status(repo: &Repo) -> i32 {
164
177
}
165
178
}
166
179
167
- 5
180
+ if is_untracked {
181
+ return Status :: Untracked ;
182
+ }
183
+
184
+ Status :: Unchange
168
185
}
169
186
170
- fn get_status_sparse ( ) -> i32 {
187
+ fn get_status_sparse ( ) -> Status {
171
188
let cmd = Command :: new ( "git" )
172
189
. arg ( "status" )
173
190
. arg ( "--porcelain" )
174
191
. output ( ) ;
175
192
176
- let mut status = 0 ;
193
+ let mut status = Status :: Unchange ;
177
194
178
195
if let Ok ( cmd) = cmd {
179
196
if cmd. status . success ( ) {
@@ -185,25 +202,23 @@ fn get_status_sparse() -> i32 {
185
202
. map ( |x| x. 0 ) ;
186
203
187
204
match out_iter. next ( ) {
188
- None => {
189
- status = 5 ;
190
- }
205
+ None => { }
191
206
Some ( x)
192
207
if MODIFY_STATUS . contains ( x)
193
208
|| MODIFY_STATUS . contains ( & x[ ..1 ] )
194
209
|| MODIFY_STATUS . contains ( & x[ 1 ..2 ] ) =>
195
210
{
196
- status = 6 ;
211
+ status = Status :: Change ;
197
212
}
198
213
Some ( "??" ) => {
199
- status = 7 ;
214
+ status = Status :: Untracked ;
200
215
}
201
216
_ => { }
202
217
}
203
218
204
219
debug ! ( "git status --porcelain output: {out}" ) ;
205
220
} else {
206
- status = 8 ;
221
+ status = Status :: HasError ;
207
222
}
208
223
}
209
224
0 commit comments