File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed
gitoxide-core/src/repository Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: OutputFormat ;
2
+ use anyhow:: bail;
3
+
4
+ pub enum Mode {
5
+ IsClean ,
6
+ IsDirty ,
7
+ }
8
+
9
+ pub fn check (
10
+ repo : gix:: Repository ,
11
+ mode : Mode ,
12
+ out : & mut dyn std:: io:: Write ,
13
+ format : OutputFormat ,
14
+ ) -> anyhow:: Result < ( ) > {
15
+ if format != OutputFormat :: Human {
16
+ bail ! ( "JSON output isn't implemented yet" ) ;
17
+ }
18
+ let is_dirty = repo. is_dirty ( ) ?;
19
+ let res = match ( is_dirty, mode) {
20
+ ( false , Mode :: IsClean ) => Ok ( "The repository is clean" ) ,
21
+ ( true , Mode :: IsClean ) => Err ( "The repository has changes" ) ,
22
+ ( false , Mode :: IsDirty ) => Err ( "The repository is clean" ) ,
23
+ ( true , Mode :: IsDirty ) => Ok ( "The repository has changes" ) ,
24
+ } ;
25
+
26
+ let suffix = "(not counting untracked files)" ;
27
+ match res {
28
+ Ok ( msg) => writeln ! ( out, "{msg} {suffix}" ) ?,
29
+ Err ( msg) => bail ! ( "{msg} {suffix}" ) ,
30
+ }
31
+ Ok ( ( ) )
32
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ pub use credential::function as credential;
26
26
pub mod attributes;
27
27
#[ cfg( feature = "clean" ) ]
28
28
pub mod clean;
29
+ pub mod dirty;
29
30
#[ cfg( feature = "clean" ) ]
30
31
pub use clean:: function:: clean;
31
32
#[ cfg( feature = "blocking-client" ) ]
Original file line number Diff line number Diff line change @@ -146,6 +146,24 @@ pub fn main() -> Result<()> {
146
146
}
147
147
148
148
match cmd {
149
+ Subcommands :: IsClean | Subcommands :: IsChanged => {
150
+ let mode = if matches ! ( cmd, Subcommands :: IsClean ) {
151
+ core:: repository:: dirty:: Mode :: IsClean
152
+ } else {
153
+ core:: repository:: dirty:: Mode :: IsDirty
154
+ } ;
155
+ prepare_and_run (
156
+ "clean" ,
157
+ trace,
158
+ verbose,
159
+ progress,
160
+ progress_keep_open,
161
+ None ,
162
+ move |_progress, out, _err| {
163
+ core:: repository:: dirty:: check ( repository ( Mode :: Lenient ) ?, mode, out, format)
164
+ } ,
165
+ )
166
+ }
149
167
#[ cfg( feature = "gitoxide-core-tools-clean" ) ]
150
168
Subcommands :: Clean ( crate :: plumbing:: options:: clean:: Command {
151
169
debug,
Original file line number Diff line number Diff line change @@ -130,6 +130,8 @@ pub enum Subcommands {
130
130
/// Interact with submodules.
131
131
#[ clap( alias = "submodules" ) ]
132
132
Submodule ( submodule:: Platform ) ,
133
+ IsClean ,
134
+ IsChanged ,
133
135
/// Show which git configuration values are used or planned.
134
136
ConfigTree ,
135
137
Status ( status:: Platform ) ,
You can’t perform that action at this time.
0 commit comments