mit_commit_message_lints/external/
config.rs1use std::{fs, path::PathBuf};
2
3use git2::Repository;
4use miette::{IntoDiagnostic, Result, WrapErr};
5
6pub fn read_toml(path: PathBuf) -> Result<String> {
12 let repository = Repository::discover(path)
13 .into_diagnostic()
14 .wrap_err("failed to work out location of repository")?;
15 let path = repository.path();
16 let bare = path.parent().unwrap_or(path).join(".git-mit.toml");
17 let dist = path.parent().unwrap_or(path).join(".git-mit.toml.dist");
18
19 if bare.exists() {
20 return fs::read_to_string(bare).into_diagnostic();
21 }
22
23 if dist.exists() {
24 return fs::read_to_string(dist).into_diagnostic();
25 }
26
27 Ok(String::new())
28}