Skip to content

Commit 6a69c41

Browse files
committed
avoid instantiating a git2 repo just to see if it is bare.
Instead, postpone the work-tree check to when it is needed and exit with the same message.
1 parent 7361a30 commit 6a69c41

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

src/info/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Info {
168168
let repo = git::discover(&config.input)?;
169169
let workdir = repo
170170
.work_dir()
171-
.context("a non-bare repository is needed")?
171+
.context("please run onefetch inside of a non-bare git repository")?
172172
.to_owned();
173173

174174
let pending_changes = std::thread::spawn({

src/info/repo.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use crate::info::head_refs::HeadRefs;
44
use anyhow::{Context, Result};
55
use byte_unit::Byte;
66
use git::bstr::BString;
7-
use git2::{Repository, RepositoryOpenFlags, Status, StatusOptions, StatusShow};
7+
use git2::{Status, StatusOptions, StatusShow};
88
use git_repository as git;
99
use git_repository::bstr::ByteSlice;
1010
use std::collections::HashMap;
11-
use std::path::Path;
12-
use std::path::PathBuf;
1311
use time::format_description::well_known::Rfc3339;
1412
use time::OffsetDateTime;
1513

@@ -299,11 +297,6 @@ where
299297
dt.into().format(&Rfc3339).unwrap()
300298
}
301299

302-
pub fn is_valid(repo_path: &PathBuf) -> Result<bool> {
303-
let repo = Repository::open_ext(repo_path, RepositoryOpenFlags::empty(), Vec::<&Path>::new());
304-
Ok(!repo?.is_bare())
305-
}
306-
307300
#[cfg(test)]
308301
mod tests {
309302
use super::*;

src/main.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![cfg_attr(feature = "fail-on-deprecated", deny(deprecated))]
22

3-
use anyhow::{bail, Result};
3+
use anyhow::Result;
44
use clap::{CommandFactory, Parser};
55
use cli::Config;
6-
use info::{repo, Info};
6+
use info::Info;
77
use std::io;
88
use ui::printer::Printer;
99

@@ -27,12 +27,7 @@ fn main() -> Result<()> {
2727
return Ok(());
2828
}
2929

30-
if !repo::is_valid(&config.input)? {
31-
bail!("please run onefetch inside of a non-bare git repository");
32-
}
33-
3430
let info = Info::new(&config)?;
35-
3631
let mut printer = Printer::new(io::BufWriter::new(io::stdout()), info, config)?;
3732

3833
printer.print()?;

0 commit comments

Comments
 (0)