@@ -26,6 +26,7 @@ struct Info {
26
26
language : Language ,
27
27
authors : Vec < String > ,
28
28
repo : String ,
29
+ commits : String ,
29
30
number_of_lines : usize ,
30
31
license : String ,
31
32
}
@@ -75,6 +76,12 @@ impl fmt::Display for Info {
75
76
}
76
77
77
78
writeln ! ( buffer, "{}{}" , "Repo: " . color( color) . bold( ) , self . repo) ?;
79
+ writeln ! (
80
+ buffer,
81
+ "{}{}" ,
82
+ "Commits: " . color( color) . bold( ) ,
83
+ self . commits
84
+ ) ?;
78
85
writeln ! (
79
86
buffer,
80
87
"{}{}" ,
@@ -226,13 +233,15 @@ fn main() -> Result<()> {
226
233
let authors = get_authors ( 3 ) ;
227
234
let config = get_configuration ( ) ?;
228
235
let version = get_version ( ) ?;
236
+ let commits = get_commits ( ) ?;
229
237
230
238
let info = Info {
231
239
project_name : config. repository_name ,
232
240
version,
233
241
language,
234
242
authors,
235
243
repo : config. repository_url ,
244
+ commits,
236
245
number_of_lines : get_total_loc ( & tokei_langs) ,
237
246
license : project_license ( ) ?,
238
247
} ;
@@ -295,6 +304,22 @@ fn get_version() -> Result<String> {
295
304
}
296
305
}
297
306
307
+ fn get_commits ( ) -> Result < String > {
308
+ let output = Command :: new ( "git" )
309
+ . arg ( "rev-list" )
310
+ . arg ( "--count" )
311
+ . arg ( "HEAD" )
312
+ . output ( )
313
+ . expect ( "Failed to execute git." ) ;
314
+
315
+ let output = String :: from_utf8_lossy ( & output. stdout ) ;
316
+
317
+ if output == "" {
318
+ Ok ( "0" . into ( ) )
319
+ } else {
320
+ Ok ( output. to_string ( ) . replace ( '\n' , "" ) )
321
+ }
322
+ }
298
323
299
324
fn is_git_installed ( ) -> bool {
300
325
Command :: new ( "git" )
0 commit comments