File tree 1 file changed +22
-14
lines changed
1 file changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -517,9 +517,8 @@ impl Info {
517
517
let output = Command :: new ( "git" )
518
518
. arg ( "-C" )
519
519
. arg ( dir)
520
- . arg ( "diff" )
521
- . arg ( "--shortstat" )
522
- . arg ( "HEAD" )
520
+ . arg ( "status" )
521
+ . arg ( "--porcelain" )
523
522
. output ( )
524
523
. expect ( "Failed to execute git." ) ;
525
524
@@ -528,17 +527,26 @@ impl Info {
528
527
if output == "" {
529
528
Ok ( "" . into ( ) )
530
529
} else {
531
- let result = String :: from ( output)
532
- . replace ( "," , & "" )
533
- . replace ( "\n " , & "" )
534
- . replace ( " files changed" , & "+-" )
535
- . replace ( " file changed" , & "+-" )
536
- . replace ( " insertions(+)" , & "+" )
537
- . replace ( " insertion(+)" , & "+" )
538
- . replace ( " deletions(-)" , & "-" )
539
- . replace ( " deletion(-)" , & "-" ) ;
540
-
541
- Ok ( result. trim ( ) . into ( ) )
530
+ let lines = output. lines ( ) ;
531
+
532
+ let mut deleted = 0 ;
533
+ let mut added = 0 ;
534
+ let mut modified = 0 ;
535
+
536
+ for line in lines {
537
+ let prefix = & line[ ..2 ] ;
538
+
539
+ match prefix. trim ( ) {
540
+ "D" => deleted += 1 ,
541
+ "A" | "??" => added += 1 ,
542
+ "M" | "MM" => modified += 1 ,
543
+ _ => { }
544
+ }
545
+ }
546
+
547
+ let result = format ! ( "{}+- {}+ {}-" , modified, added, deleted) ;
548
+
549
+ Ok ( result. into ( ) )
542
550
}
543
551
}
544
552
You can’t perform that action at this time.
0 commit comments