@@ -27,6 +27,7 @@ pub struct Info {
27
27
last_change : String ,
28
28
repo : String ,
29
29
commits : String ,
30
+ changes : String ,
30
31
repo_size : String ,
31
32
number_of_lines : usize ,
32
33
license : String ,
@@ -191,6 +192,14 @@ impl std::fmt::Display for Info {
191
192
) ?;
192
193
}
193
194
195
+ if !self . disable_fields . changes && self . changes != "" {
196
+ write_buf (
197
+ & mut buf,
198
+ & self . get_formatted_info_label ( "Changes: " , color) ,
199
+ & self . changes ,
200
+ ) ?;
201
+ }
202
+
194
203
if !self . disable_fields . lines_of_code {
195
204
write_buf (
196
205
& mut buf,
@@ -304,6 +313,7 @@ impl Info {
304
313
let ( git_v, git_user) = Info :: get_git_info ( workdir_str) ;
305
314
let version = Info :: get_version ( workdir_str) ?;
306
315
let commits = Info :: get_commits ( workdir_str, no_merges) ?;
316
+ let changes = Info :: get_pending_changes ( workdir_str) ?;
307
317
let repo_size = Info :: get_packed_size ( workdir_str) ?;
308
318
let last_change = Info :: get_last_change ( workdir_str) ?;
309
319
let creation_date = Info :: get_creation_time ( workdir_str) ?;
@@ -324,6 +334,7 @@ impl Info {
324
334
last_change,
325
335
repo : config. repository_url ,
326
336
commits,
337
+ changes,
327
338
repo_size,
328
339
number_of_lines,
329
340
license : project_license,
@@ -502,6 +513,35 @@ impl Info {
502
513
}
503
514
}
504
515
516
+ fn get_pending_changes ( dir : & str ) -> Result < String > {
517
+ let output = Command :: new ( "git" )
518
+ . arg ( "-C" )
519
+ . arg ( dir)
520
+ . arg ( "diff" )
521
+ . arg ( "--shortstat" )
522
+ . arg ( "HEAD" )
523
+ . output ( )
524
+ . expect ( "Failed to execute git." ) ;
525
+
526
+ let output = String :: from_utf8_lossy ( & output. stdout ) ;
527
+
528
+ if output == "" {
529
+ Ok ( "" . into ( ) )
530
+ } 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 ( ) )
542
+ }
543
+ }
544
+
505
545
fn get_packed_size ( dir : & str ) -> Result < String > {
506
546
let output = Command :: new ( "git" )
507
547
. arg ( "-C" )
0 commit comments