1
1
use {
2
2
crate :: onefetch:: {
3
- cli:: Cli , commit_info:: CommitInfo , deps, error:: * , git_utils , language:: Language ,
4
- license :: Detector , text_color:: TextColor ,
3
+ cli:: Cli , commit_info:: CommitInfo , deps, error:: * , language:: Language , license :: Detector ,
4
+ repo :: Repo , text_color:: TextColor ,
5
5
} ,
6
6
colored:: { Color , ColoredString , Colorize } ,
7
- git2:: Repository ,
8
7
std:: process:: Command ,
9
8
} ;
10
9
@@ -83,7 +82,7 @@ impl std::fmt::Display for Info {
83
82
) ?;
84
83
}
85
84
86
- if !self . config . disabled_fields . version {
85
+ if !self . config . disabled_fields . version && ! self . version . is_empty ( ) {
87
86
writeln ! (
88
87
f,
89
88
"{}{}" ,
@@ -211,19 +210,19 @@ impl std::fmt::Display for Info {
211
210
212
211
impl Info {
213
212
pub fn new ( config : Cli ) -> Result < Info > {
214
- let repo = Repository :: discover ( & config. repo_path ) ?;
215
- let workdir = git_utils:: get_repo_work_dir ( & repo) ?;
216
- let ( repository_name, repository_url) = git_utils:: get_repo_name_and_url ( & repo) ?;
217
- let current_commit_info = git_utils:: get_current_commit_info ( & repo) ;
218
- let pending = git_utils:: get_pending_changes ( & repo) ;
213
+ let repo = Repo :: new ( & config. repo_path ) ?;
214
+ let workdir = repo. get_work_dir ( ) ?;
215
+ let ( repository_name, repository_url) = repo. get_name_and_url ( ) ?;
216
+ let current_commit_info = repo. get_current_commit_info ( ) ;
217
+ let pending = repo. get_pending_changes ( ) ;
218
+ let version = repo. get_version ( ) ?;
219
219
let git_history = Info :: get_git_history ( & workdir, config. no_merges ) ;
220
220
let creation_date = Info :: get_creation_date ( & git_history) ;
221
221
let number_of_commits = Info :: get_number_of_commits ( & git_history) ;
222
222
let authors = Info :: get_authors ( & git_history, config. number_of_authors ) ;
223
223
let last_change = Info :: get_date_of_last_commit ( & git_history) ;
224
224
let ( number_of_tags, number_of_branches) = Info :: get_number_of_tags_branches ( & workdir) ;
225
225
let ( git_v, git_user) = Info :: get_git_version_and_username ( & workdir) ;
226
- let version = Info :: get_version ( & workdir) ;
227
226
let repo_size = Info :: get_packed_size ( & workdir) ;
228
227
let project_license = Detector :: new ( ) ?. get_project_license ( & workdir) ;
229
228
let dependencies = deps:: DependencyDetector :: new ( ) . get_dependencies ( & workdir) ?;
@@ -243,7 +242,7 @@ impl Info {
243
242
git_username : git_user,
244
243
project_name : repository_name,
245
244
current_commit : current_commit_info?,
246
- version : version? ,
245
+ version,
247
246
creation_date : creation_date?,
248
247
dominant_language,
249
248
languages : languages_stats,
@@ -357,25 +356,6 @@ impl Info {
357
356
( version, username)
358
357
}
359
358
360
- fn get_version ( dir : & str ) -> Result < String > {
361
- let output = Command :: new ( "git" )
362
- . arg ( "-C" )
363
- . arg ( dir)
364
- . arg ( "describe" )
365
- . arg ( "--abbrev=0" )
366
- . arg ( "--tags" )
367
- . output ( )
368
- . expect ( "Failed to execute git." ) ;
369
-
370
- let output = String :: from_utf8_lossy ( & output. stdout ) ;
371
-
372
- if output == "" {
373
- Ok ( "??" . into ( ) )
374
- } else {
375
- Ok ( output. to_string ( ) . replace ( '\n' , "" ) )
376
- }
377
- }
378
-
379
359
fn get_number_of_commits ( git_history : & [ String ] ) -> String {
380
360
let number_of_commits = git_history. len ( ) ;
381
361
number_of_commits. to_string ( )
0 commit comments