Skip to content

Commit

Permalink
Store Repository in git config struct
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Jul 22, 2020
1 parent 142fdbd commit 29bf022
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/git_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use git2;
pub struct GitConfig {
config: git2::Config,
pub enabled: bool,
pub repo: Option<git2::Repository>,
}

impl GitConfig {
Expand All @@ -15,7 +16,7 @@ impl GitConfig {
Ok(dir) => git2::Repository::discover(dir).ok(),
_ => None,
};
let config = match repo {
let config = match &repo {
Some(repo) => repo.config().ok(),
None => git2::Config::open_default().ok(),
};
Expand All @@ -27,6 +28,7 @@ impl GitConfig {
});
Some(Self {
config,
repo,
enabled: true,
})
}
Expand All @@ -38,6 +40,7 @@ impl GitConfig {
pub fn from_path(path: &Path) -> Self {
Self {
config: git2::Config::open(path).unwrap(),
repo: None,
enabled: true,
}
}
Expand Down

0 comments on commit 29bf022

Please sign in to comment.