Skip to content

Commit

Permalink
Enhance Committer to navigate to repo root, improving usability
Browse files Browse the repository at this point in the history
  • Loading branch information
kazzix14 committed Mar 4, 2024
1 parent e03c47b commit 14e4ed1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::comment_generator::CommentGenerator;
use crate::confirmor::Confirmor;

use std::io::Read;
use std::path::Path;
use std::{fmt::Write, io::BufRead};

use git2::{DiffFormat, DiffOptions, Repository};
Expand All @@ -14,6 +15,13 @@ pub struct Committer {

impl Committer {
pub fn new(confirmor: Confirmor, comment_generator: CommentGenerator) -> anyhow::Result<Self> {
while let Err(err) = Repository::open(".") {
if let Some(parent) = Path::new("..").canonicalize().ok() {
std::env::set_current_dir(parent)?;
} else {
return Err(err.into());
}
}
let repository = Repository::open(".")?;

Ok(Committer {
Expand Down

0 comments on commit 14e4ed1

Please sign in to comment.