@@ -14,6 +14,8 @@ use crate::{AsciiArt, CommitInfo, Configuration, Error, InfoFieldOn};
14
14
type Result < T > = std:: result:: Result < T , crate :: Error > ;
15
15
16
16
pub struct Info {
17
+ git_version : String ,
18
+ git_username : String ,
17
19
project_name : String ,
18
20
current_commit : CommitInfo ,
19
21
version : String ,
@@ -39,7 +41,13 @@ impl std::fmt::Display for Info {
39
41
Some ( & c) => c,
40
42
None => Color :: White ,
41
43
} ;
42
-
44
+ if !self . disable_fields . git_info {
45
+ let mut git_info = String :: from ( & self . git_username ) ;
46
+ git_info. push ( ':' ) ;
47
+ git_info. push_str ( & self . git_version ) ;
48
+ write_buf ( & mut buf, "" , & git_info, color) ?;
49
+ write_buf ( & mut buf, "" , "--------------" , color) ?;
50
+ }
43
51
if !self . disable_fields . project {
44
52
write_buf ( & mut buf, "Project: " , & self . project_name , color) ?;
45
53
}
@@ -187,6 +195,7 @@ impl Info {
187
195
disabled : InfoFieldOn ,
188
196
) -> Result < Info > {
189
197
let authors = Info :: get_authors ( & dir, 3 ) ;
198
+ let ( git_v, git_user) = Info :: get_git_info ( ) ;
190
199
let current_commit_info = Info :: get_current_commit_info ( & dir) ?;
191
200
let config = Info :: get_configuration ( & dir) ?;
192
201
let version = Info :: get_version ( & dir) ?;
@@ -199,6 +208,8 @@ impl Info {
199
208
let dominant_language = Language :: get_dominant_language ( languages_stats. clone ( ) ) ;
200
209
201
210
Ok ( Info {
211
+ git_version : git_v,
212
+ git_username : git_user,
202
213
project_name : config. repository_name ,
203
214
current_commit : current_commit_info,
204
215
version,
@@ -262,6 +273,25 @@ impl Info {
262
273
authors
263
274
}
264
275
276
+ fn get_git_info ( ) -> ( String , String ) {
277
+ let version = Command :: new ( "git" )
278
+ . arg ( "--version" )
279
+ . output ( )
280
+ . expect ( "Failed to execute git." ) ;
281
+ let version = String :: from_utf8_lossy ( & version. stdout ) ;
282
+ let version = version. to_string ( ) . replace ( '\n' , "" ) ;
283
+
284
+ let username = Command :: new ( "git" )
285
+ . arg ( "config" )
286
+ . arg ( "--get" )
287
+ . arg ( "user.name" )
288
+ . output ( )
289
+ . expect ( "Failed to execute git." ) ;
290
+ let username = String :: from_utf8_lossy ( & username. stdout ) ;
291
+ let username = username. to_string ( ) . replace ( '\n' , "" ) ;
292
+ ( version, username)
293
+ }
294
+
265
295
fn get_current_commit_info ( dir : & str ) -> Result < CommitInfo > {
266
296
let repo = Repository :: open ( dir) . map_err ( |_| Error :: NotGitRepo ) ?;
267
297
let head = repo. head ( ) . map_err ( |_| Error :: ReferenceInfoError ) ?;
0 commit comments