From d2796de90a664115b5e9bbcc346d363b72e9d964 Mon Sep 17 00:00:00 2001 From: xli-oai Date: Mon, 13 Apr 2026 02:18:06 -0700 Subject: [PATCH] Fix marketplace auto-upgrade revision tracking --- .../core/src/plugins/marketplace_upgrade.rs | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/plugins/marketplace_upgrade.rs b/codex-rs/core/src/plugins/marketplace_upgrade.rs index dee975d6c6..d3b51da9c1 100644 --- a/codex-rs/core/src/plugins/marketplace_upgrade.rs +++ b/codex-rs/core/src/plugins/marketplace_upgrade.rs @@ -180,7 +180,7 @@ fn upgrade_configured_git_marketplace( ) })?; - clone_git_source( + let activated_revision = clone_git_source( &marketplace.source, marketplace.ref_name.as_deref(), &marketplace.sparse_paths, @@ -195,12 +195,12 @@ fn upgrade_configured_git_marketplace( marketplace.name )); } - write_activated_marketplace_metadata(staged_dir.path(), marketplace, &remote_revision)?; + write_activated_marketplace_metadata(staged_dir.path(), marketplace, &activated_revision)?; let last_updated = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true); let update = MarketplaceConfigUpdate { last_updated: &last_updated, - last_revision: Some(&remote_revision), + last_revision: Some(&activated_revision), source_type: "git", source: &marketplace.source, ref_name: marketplace.ref_name.as_deref(), @@ -373,7 +373,7 @@ fn clone_git_source( sparse_paths: &[String], destination: &Path, timeout: Duration, -) -> Result<(), String> { +) -> Result { if sparse_paths.is_empty() { let output = run_git_command_with_timeout( git_command().arg("clone").arg(source).arg(destination), @@ -393,7 +393,7 @@ fn clone_git_source( )?; ensure_git_success(&output, "git checkout marketplace ref")?; } - return Ok(()); + return git_worktree_revision(destination, timeout); } let output = run_git_command_with_timeout( @@ -431,7 +431,28 @@ fn clone_git_source( "git checkout marketplace ref", timeout, )?; - ensure_git_success(&output, "git checkout marketplace ref") + ensure_git_success(&output, "git checkout marketplace ref")?; + git_worktree_revision(destination, timeout) +} + +fn git_worktree_revision(destination: &Path, timeout: Duration) -> Result { + let output = run_git_command_with_timeout( + git_command() + .arg("-C") + .arg(destination) + .arg("rev-parse") + .arg("HEAD"), + "git rev-parse marketplace revision", + timeout, + )?; + ensure_git_success(&output, "git rev-parse marketplace revision")?; + + let revision = String::from_utf8_lossy(&output.stdout).trim().to_string(); + if revision.is_empty() { + Err("git rev-parse returned empty revision for marketplace source".to_string()) + } else { + Ok(revision) + } } fn git_command() -> Command {