From d58a4349b69b39a312add436db2ffe9c9c906fdc Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Mon, 18 May 2026 00:13:05 +0530 Subject: [PATCH] test: verify git2 crate integration compiles correctly Fix git2 v0.19 API compatibility issues: - Replace deprecated .foreach() with idiomatic for-loop iterator - Rename shadowed statuses variable to avoid shadowing the result vector - Fix diff.print callback signature: use _hunk instead of _origin Co-Authored-By: Claude Opus 4.7 --- src-tauri/src/commands/git.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/commands/git.rs b/src-tauri/src/commands/git.rs index 4a53b1d..1a43f15 100644 --- a/src-tauri/src/commands/git.rs +++ b/src-tauri/src/commands/git.rs @@ -5,12 +5,13 @@ use crate::error::AppError; #[tauri::command] pub async fn git_status(repo_path: String) -> CommandResult, AppError> { let repo = Repository::open(&repo_path).map_err(|e| AppError::Git(e.to_string()))?; - let mut statuses = Vec::new(); + let mut entries = Vec::new(); - repo.statuses(None).map_err(|e| AppError::Git(e.to_string()))?.foreach(|entry| { + let statuses = repo.statuses(None).map_err(|e| AppError::Git(e.to_string()))?; + for entry in statuses.iter() { if let Some(status) = entry.status() { let path = entry.path().unwrap_or("").to_string(); - statuses.push(GitStatusEntry { + entries.push(GitStatusEntry { path, is_staged: status.intersects(Status::INDEX_NEW | Status::INDEX_MODIFIED | Status::INDEX_DELETED), is_modified: status.intersects(Status::WT_MODIFIED), @@ -18,10 +19,9 @@ pub async fn git_status(repo_path: String) -> CommandResult, is_deleted: status.intersects(Status::WT_DELETED), }); } - true - }).map_err(|e| AppError::Git(e.to_string()))?; + } - Ok(statuses) + Ok(entries) } #[derive(serde::Serialize)] @@ -97,7 +97,7 @@ pub async fn git_diff(repo_path: String, path: Option) -> CommandResult< let diff = repo.diff_index_to_workdir(None, Some(&mut opts)) .map_err(|e| AppError::Git(e.to_string()))?; let mut out = Vec::new(); - diff.print(git2::DiffFormat::Patch, |_delta, _origin, line| { + diff.print(git2::DiffFormat::Patch, |_delta, _hunk, line| { let prefix = match line.origin() { '+' => " +", '-' => " -",