From 0cc3b502287dd79265920ff08b2e2648411ed161 Mon Sep 17 00:00:00 2001 From: Ali Towaiji <145403626+Towaiji@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:14:36 -0500 Subject: [PATCH] Fix recent_commits(limit=0) returning 1 commit instead of 0 (#7334) Fixes #7333 This is a small bug fix. This PR fixes an inconsistency in `recent_commits` where `limit == 0` still returns 1 commit due to the use of `limit.max(1)` when constructing the `git log -n` argument. Expected behavior: requesting 0 commits should return an empty list. This PR: - returns an empty `Vec` when `limit == 0` - adds a test for `recent_commits(limit == 0)` that fails before the change and passes afterwards - maintains existing behavior for `limit > 0` This aligns behavior with API expectations and avoids downstream consumers misinterpreting the repository as having commit history when `limit == 0` is used to explicitly request none. Happy to adjust if the current behavior is intentional. --- codex-rs/core/src/git_info.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/codex-rs/core/src/git_info.rs b/codex-rs/core/src/git_info.rs index 34e0afc72..4284ff126 100644 --- a/codex-rs/core/src/git_info.rs +++ b/codex-rs/core/src/git_info.rs @@ -131,11 +131,15 @@ pub async fn recent_commits(cwd: &Path, limit: usize) -> Vec { } let fmt = "%H%x1f%ct%x1f%s"; // - let n = limit.max(1).to_string(); - let Some(log_out) = - run_git_command_with_timeout(&["log", "-n", &n, &format!("--pretty=format:{fmt}")], cwd) - .await - else { + let limit_arg = (limit > 0).then(|| limit.to_string()); + let mut args: Vec = vec!["log".to_string()]; + if let Some(n) = &limit_arg { + args.push("-n".to_string()); + args.push(n.clone()); + } + args.push(format!("--pretty=format:{fmt}")); + let arg_refs: Vec<&str> = args.iter().map(String::as_str).collect(); + let Some(log_out) = run_git_command_with_timeout(&arg_refs, cwd).await else { return Vec::new(); }; if !log_out.status.success() {