-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
gix free discover
to inform about repository discovery.
It's mainly to better understand what's causing certain failures if a repository can't be opened, in different modes of operations.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::Path; | ||
|
||
pub fn discover(repo: &Path, mut out: impl std::io::Write) -> anyhow::Result<()> { | ||
let mut has_err = false; | ||
writeln!(out, "open (strict) {}:", repo.display())?; | ||
has_err |= print_result( | ||
&mut out, | ||
gix::open_opts(repo, gix::open::Options::default().strict_config(true)), | ||
)?; | ||
|
||
if has_err { | ||
writeln!(out, "open (lenient) {}:", repo.display())?; | ||
has_err |= print_result( | ||
&mut out, | ||
gix::open_opts(repo, gix::open::Options::default().strict_config(false)), | ||
)?; | ||
} | ||
|
||
writeln!(out)?; | ||
writeln!(out, "discover from {}:", repo.display())?; | ||
has_err |= print_result(&mut out, gix::discover(repo))?; | ||
|
||
writeln!(out)?; | ||
writeln!(out, "discover (plumbing) from {}:", repo.display())?; | ||
has_err |= print_result(&mut out, gix::discover::upwards(repo))?; | ||
|
||
if has_err { | ||
writeln!(out)?; | ||
anyhow::bail!("At least one operation failed") | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn print_result<T, E>(mut out: impl std::io::Write, res: Result<T, E>) -> std::io::Result<bool> | ||
where | ||
T: std::fmt::Debug, | ||
E: std::error::Error + Send + Sync + 'static, | ||
{ | ||
let mut has_err = false; | ||
let to_print = match res { | ||
Ok(good) => { | ||
format!("{good:#?}") | ||
} | ||
Err(err) => { | ||
has_err = true; | ||
format!("{:?}", anyhow::Error::from(err)) | ||
} | ||
}; | ||
indent(&mut out, to_print)?; | ||
Ok(has_err) | ||
} | ||
|
||
fn indent(mut out: impl std::io::Write, msg: impl Into<String>) -> std::io::Result<()> { | ||
for line in msg.into().lines() { | ||
writeln!(out, "\t{line}")?; | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters