File tree 2 files changed +21
-3
lines changed 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ pub fn cli() -> App {
30
30
. arg_target_dir ( )
31
31
. arg_manifest_path ( )
32
32
. arg_message_format ( )
33
+ . arg (
34
+ Arg :: with_name ( "allow-staged" )
35
+ . long ( "allow-staged" )
36
+ . help ( "Fix code that has been staged for committing" ) ,
37
+ )
33
38
. arg (
34
39
Arg :: with_name ( "broken-code" )
35
40
. long ( "broken-code" )
@@ -136,6 +141,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
136
141
allow_dirty : args. is_present ( "allow-dirty" ) ,
137
142
allow_no_vcs : args. is_present ( "allow-no-vcs" ) ,
138
143
broken_code : args. is_present ( "broken-code" ) ,
144
+ allow_staged : args. is_present ( "allow-staged" ) ,
139
145
} ) ?;
140
146
Ok ( ( ) )
141
147
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ pub struct FixOptions<'a> {
34
34
pub allow_dirty : bool ,
35
35
pub allow_no_vcs : bool ,
36
36
pub broken_code : bool ,
37
+ pub allow_staged : bool ,
37
38
}
38
39
39
40
pub fn fix ( ws : & Workspace , opts : & mut FixOptions ) -> CargoResult < ( ) > {
@@ -93,10 +94,21 @@ fn check_version_control(opts: &FixOptions) -> CargoResult<()> {
93
94
94
95
let mut dirty_files = Vec :: new ( ) ;
95
96
if let Ok ( repo) = git2:: Repository :: discover ( config. cwd ( ) ) {
96
- let mut opts = git2:: StatusOptions :: new ( ) ;
97
- opts . include_ignored ( false ) ;
98
- for status in repo. statuses ( Some ( & mut opts ) ) ?. iter ( ) {
97
+ let mut git_opts = git2:: StatusOptions :: new ( ) ;
98
+ git_opts . include_ignored ( false ) ;
99
+ for status in repo. statuses ( Some ( & mut git_opts ) ) ?. iter ( ) {
99
100
if status. status ( ) != git2:: Status :: CURRENT {
101
+ if opts. allow_staged {
102
+ if status. status ( ) == git2:: Status :: INDEX_NEW
103
+ || status. status ( ) == git2:: Status :: INDEX_MODIFIED
104
+ || status. status ( ) == git2:: Status :: INDEX_DELETED
105
+ || status. status ( ) == git2:: Status :: INDEX_RENAMED
106
+ || status. status ( ) == git2:: Status :: INDEX_TYPECHANGE
107
+ {
108
+ continue ;
109
+ }
110
+ }
111
+
100
112
if let Some ( path) = status. path ( ) {
101
113
dirty_files. push ( path. to_string ( ) ) ;
102
114
}
You can’t perform that action at this time.
0 commit comments