Skip to content

Commit 3162a2c

Browse files
bashandboneclaude
andcommitted
fix: propagate fetch errors from gix to enable git2 fallback
The fetch_repo function silently swallowed errors via eprintln, preventing the git2 fallback from triggering on gix fetch failures (e.g., SSL certificate verifier misconfiguration). Made get_progress generic so closures can return Results, and propagated the fetch error. Added 23 fallback architecture tests covering error propagation, backend consistency, reopen behavior, and the gix->git2->CLI chain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 30e3834 commit 3162a2c

2 files changed

Lines changed: 698 additions & 17 deletions

File tree

src/git_ops/simple_gix.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ pub fn progress_tree(trace: bool) -> std::sync::Arc<prodash::tree::Root> {
4646
}
4747

4848
/// Run a function with progress tracking, capturing output to stdout and stderr.
49-
pub fn get_progress(
49+
pub fn get_progress<T>(
5050
func_name: &str,
5151
range: Option<std::ops::RangeInclusive<u8>>,
5252
run: impl FnOnce(
5353
progress::DoOrDiscard<prodash::tree::Item>,
5454
&mut dyn std::io::Write,
5555
&mut dyn std::io::Write,
56-
),
57-
) -> Result<()> {
56+
) -> T,
57+
) -> Result<T> {
5858
let standard_range = 2..=2;
5959
let range = range.unwrap_or_else(|| standard_range.clone());
6060
let progress = progress_tree(false);
@@ -65,7 +65,7 @@ pub fn get_progress(
6565
let mut out = Vec::<u8>::new();
6666
let mut err = Vec::<u8>::new();
6767

68-
let _res = gix::trace::coarse!("run").into_scope(|| {
68+
let result = gix::trace::coarse!("run").into_scope(|| {
6969
run(
7070
progress::DoOrDiscard::from(Some(sub_progress)),
7171
&mut out,
@@ -76,7 +76,7 @@ pub fn get_progress(
7676
handle.shutdown_and_wait();
7777
std::io::Write::write_all(&mut stdout(), &out)?;
7878
std::io::Write::write_all(&mut stderr(), &err)?;
79-
Ok(())
79+
Ok(result)
8080
}
8181

8282
/// Fetch options for the `fetch` command, with an option for shallow fetching.
@@ -100,16 +100,15 @@ fn fetch_options(remote: Option<String>, shallow: bool) -> FetchOptions {
100100

101101
/// Fetch updates from a remote repository.
102102
pub fn fetch_repo(repo: gix::Repository, remote: Option<String>, shallow: bool) -> Result<()> {
103-
get_progress("fetch", Some(FetchProgressRange), |progress, out, err| {
104-
if let Err(e) = gitoxide_core::repository::fetch(
105-
repo,
106-
progress,
107-
out,
108-
err,
109-
fetch_options(remote, shallow),
110-
) {
111-
// Optionally print error to stderr directly
112-
eprintln!("Fetch failed: {:?}", e);
113-
}
114-
})
103+
let inner_result =
104+
get_progress("fetch", Some(FetchProgressRange), |progress, out, err| {
105+
gitoxide_core::repository::fetch(
106+
repo,
107+
progress,
108+
out,
109+
err,
110+
fetch_options(remote, shallow),
111+
)
112+
})?;
113+
inner_result.map_err(|e| anyhow::anyhow!("Fetch failed: {e}"))
115114
}

0 commit comments

Comments
 (0)