Skip to content

Commit 790a85c

Browse files
committedNov 1, 2019
Improve running command from subfolder
1 parent 654a726 commit 790a85c

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed
 

Diff for: ‎src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub enum Error {
1111
/// Not in a Git Repo
1212
NotGitRepo,
1313
/// Error while getting branch info
14+
BareGitRepo,
15+
/// Repository is a bare git repo
1416
ReferenceInfoError,
1517
/// Image probably doesn't exist or has wrong format
1618
ImageLoadError,
@@ -24,6 +26,7 @@ impl std::fmt::Debug for Error {
2426
Error::NoGitData => "Could not retrieve git configuration data",
2527
Error::ReadDirectory => "Could not read directory",
2628
Error::NotGitRepo => "Could not find a valid git repo on the current path",
29+
Error::BareGitRepo => "Unable to run onefetch on bare git repos",
2730
Error::ReferenceInfoError => "Error while retrieving reference information",
2831
Error::ImageLoadError => "Could not load the specified image",
2932
};

Diff for: ‎src/info.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,21 @@ impl Info {
288288
custom_image: Option<DynamicImage>,
289289
no_merges: bool,
290290
) -> Result<Info> {
291-
let authors = Info::get_authors(&dir, no_merges, 3);
292-
let (git_v, git_user) = Info::get_git_info(&dir);
293-
let current_commit_info = Info::get_current_commit_info(&dir)?;
294-
let config = Info::get_configuration(&dir)?;
295-
let version = Info::get_version(&dir)?;
296-
let commits = Info::get_commits(&dir, no_merges)?;
297-
let repo_size = Info::get_packed_size(&dir)?;
298-
let last_change = Info::get_last_change(&dir)?;
299-
let creation_date = Info::get_creation_time(dir)?;
300-
let project_license = Info::get_project_license(&dir)?;
301-
let (languages_stats, number_of_lines) = Language::get_language_stats(&dir)?;
291+
let repo = Repository::discover(&dir).map_err(|_| Error::NotGitRepo)?;
292+
let workdir = repo.workdir().ok_or(Error::BareGitRepo)?;
293+
let workdir_str = workdir.to_str().unwrap();
294+
295+
let authors = Info::get_authors(workdir_str, no_merges, 3);
296+
let (git_v, git_user) = Info::get_git_info(workdir_str);
297+
let current_commit_info = Info::get_current_commit_info(&repo)?;
298+
let config = Info::get_configuration(&repo)?;
299+
let version = Info::get_version(workdir_str)?;
300+
let commits = Info::get_commits(workdir_str, no_merges)?;
301+
let repo_size = Info::get_packed_size(workdir_str)?;
302+
let last_change = Info::get_last_change(workdir_str)?;
303+
let creation_date = Info::get_creation_time(workdir_str)?;
304+
let project_license = Info::get_project_license(workdir_str)?;
305+
let (languages_stats, number_of_lines) = Language::get_language_stats(workdir_str)?;
302306
let dominant_language = Language::get_dominant_language(languages_stats.clone());
303307

304308
Ok(Info {
@@ -390,8 +394,7 @@ impl Info {
390394
(version, username)
391395
}
392396

393-
fn get_current_commit_info(dir: &str) -> Result<CommitInfo> {
394-
let repo = Repository::discover(dir).map_err(|_| Error::NotGitRepo)?;
397+
fn get_current_commit_info(repo: &Repository) -> Result<CommitInfo> {
395398
let head = repo.head().map_err(|_| Error::ReferenceInfoError)?;
396399
let head_oid = head.target().ok_or(Error::ReferenceInfoError)?;
397400
let refs = repo.references().map_err(|_| Error::ReferenceInfoError)?;
@@ -413,8 +416,7 @@ impl Info {
413416
Ok(CommitInfo::new(head_oid, refs_info))
414417
}
415418

416-
fn get_configuration(dir: &str) -> Result<Configuration> {
417-
let repo = Repository::discover(dir).map_err(|_| Error::NotGitRepo)?;
419+
fn get_configuration(repo: &Repository) -> Result<Configuration> {
418420
let config = repo.config().map_err(|_| Error::NoGitData)?;
419421
let mut remote_url = String::new();
420422
let mut repository_name = String::new();

0 commit comments

Comments
 (0)
Please sign in to comment.