@@ -32,6 +32,8 @@ pub struct Info {
32
32
pending : String ,
33
33
repo_size : String ,
34
34
number_of_lines : usize ,
35
+ number_of_tags : usize ,
36
+ number_of_branches : usize ,
35
37
license : String ,
36
38
custom_logo : Language ,
37
39
custom_colors : Vec < String > ,
@@ -74,10 +76,38 @@ impl std::fmt::Display for Info {
74
76
) ?;
75
77
}
76
78
if !self . disable_fields . project {
77
- write_buf (
78
- & mut buf,
79
- & self . get_formatted_info_label ( "Project: " , color) ,
80
- & self . project_name ,
79
+ let branches_str = if self . number_of_branches == 1 {
80
+ String :: from ( "1 branch" )
81
+ } else if self . number_of_branches > 1 {
82
+ format ! ( "{} branches" , self . number_of_branches)
83
+ } else {
84
+ String :: new ( )
85
+ } ;
86
+
87
+ let tags_str = if self . number_of_tags == 1 {
88
+ String :: from ( "1 tag" )
89
+ } else if self . number_of_tags > 1 {
90
+ format ! ( "{} tags" , self . number_of_tags)
91
+ } else {
92
+ String :: new ( )
93
+ } ;
94
+
95
+ let branches_tags_str = if tags_str. is_empty ( ) && !branches_str. is_empty ( ) {
96
+ format ! ( "( {} )" , branches_str)
97
+ } else if branches_str. is_empty ( ) && !tags_str. is_empty ( ) {
98
+ format ! ( "( {} )" , tags_str)
99
+ } else if !branches_str. is_empty ( ) {
100
+ format ! ( "( {}, {} )" , tags_str, branches_str)
101
+ } else {
102
+ String :: new ( )
103
+ } ;
104
+
105
+ let project_str = & self . get_formatted_info_label ( "Project: " , color) ;
106
+
107
+ writeln ! (
108
+ buf,
109
+ "{}{} {}" ,
110
+ project_str, self . project_name, branches_tags_str
81
111
) ?;
82
112
}
83
113
@@ -309,6 +339,7 @@ impl Info {
309
339
let (
310
340
( repository_name, repository_url) ,
311
341
git_history,
342
+ ( number_of_tags, number_of_branches) ,
312
343
current_commit_info,
313
344
( git_v, git_user) ,
314
345
version,
@@ -319,6 +350,7 @@ impl Info {
319
350
) = futures:: join!(
320
351
Info :: get_repo_name_and_url( & repo) ,
321
352
Info :: get_git_history( workdir_str, no_merges) ,
353
+ Info :: get_number_of_tags_branches( workdir_str) ,
322
354
Info :: get_current_commit_info( & repo) ,
323
355
Info :: get_git_version_and_username( workdir_str) ,
324
356
Info :: get_version( workdir_str) ,
@@ -349,6 +381,8 @@ impl Info {
349
381
pending : pending?,
350
382
repo_size : repo_size?,
351
383
number_of_lines,
384
+ number_of_tags,
385
+ number_of_branches,
352
386
license : project_license?,
353
387
custom_logo : logo,
354
388
custom_colors : colors,
@@ -378,6 +412,34 @@ impl Info {
378
412
output. lines ( ) . map ( |x| x. to_string ( ) ) . collect :: < Vec < _ > > ( )
379
413
}
380
414
415
+ async fn get_number_of_tags_branches ( dir : & str ) -> ( usize , usize ) {
416
+ let tags = async {
417
+ let output = Command :: new ( "git" )
418
+ . args ( vec ! [ "-C" , dir, "tag" ] )
419
+ . output ( )
420
+ . await
421
+ . expect ( "Failed to execute git." ) ;
422
+
423
+ let tags = String :: from_utf8_lossy ( & output. stdout ) ;
424
+
425
+ tags. lines ( ) . count ( )
426
+ } ;
427
+
428
+ let branches = async {
429
+ let output = Command :: new ( "git" )
430
+ . args ( vec ! [ "-C" , dir, "branch" , "-r" ] )
431
+ . output ( )
432
+ . await
433
+ . expect ( "Failed to execute git." ) ;
434
+
435
+ let branches = String :: from_utf8_lossy ( & output. stdout ) ;
436
+
437
+ branches. lines ( ) . count ( )
438
+ } ;
439
+
440
+ futures:: join!( tags, branches)
441
+ }
442
+
381
443
async fn get_repo_name_and_url ( repo : & Repository ) -> ( String , String ) {
382
444
let config = repo. config ( ) . map_err ( |_| Error :: NoGitData ) ;
383
445
let mut remote_url = String :: new ( ) ;
0 commit comments