From b07424f87185fd0e4ee3d5c472df70e5f575a259 Mon Sep 17 00:00:00 2001 From: soryu Date: Thu, 29 Jan 2026 17:14:09 +0000 Subject: Fetch from origin before creating worktrees for local repos (#49) * Add comprehensive Red Team system specification Defines the adversarial review feature for contracts that monitors work tasks in real-time to catch quality issues, plan deviations, and standards violations. Key components specified: - Contract configuration (red_team_enabled, red_team_prompt) - Red team task lifecycle and spawning logic - makima red-team notify CLI command for supervisor alerts - Task output subscription for real-time monitoring - Database schema changes (contracts, tasks, notifications table) - API endpoints for notification and status - System prompt template for red team behavior - Security considerations and access control Co-Authored-By: Claude Opus 4.5 * Task completion checkpoint * Task completion checkpoint * Task completion checkpoint * feat: fetch from origin for local repos before creating worktrees When a supervisor creates worktrees from a local repository that tracks a remote origin, it may use stale data. This change ensures that for local repositories with an origin remote configured, we explicitly fetch from origin before creating worktrees. Changes: - Check if 'origin' remote exists using `git remote get-url origin` - If origin exists, fetch from it with `git fetch origin` - Log appropriately whether it's a remote-backed or local-only repository - Keep the behavior non-fatal (don't fail if fetch fails, just log) - Keep existing `git fetch --all --prune` as fallback for other remotes Co-Authored-By: Claude Opus 4.5 --------- Co-authored-by: Claude Opus 4.5 --- makima/src/daemon/worktree/manager.rs | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/makima/src/daemon/worktree/manager.rs b/makima/src/daemon/worktree/manager.rs index fa8a9de..166e654 100644 --- a/makima/src/daemon/worktree/manager.rs +++ b/makima/src/daemon/worktree/manager.rs @@ -256,8 +256,37 @@ impl WorktreeManager { ))); } - // Fetch latest changes from remote if configured - tracing::info!("Fetching latest changes for local repo: {}", repo_source); + // Check if 'origin' remote exists + let origin_check = Command::new("git") + .args(["remote", "get-url", "origin"]) + .current_dir(&path) + .output() + .await; + + let has_origin = origin_check + .map(|o| o.status.success()) + .unwrap_or(false); + + if has_origin { + // Fetch from origin specifically to get the latest changes + tracing::info!("Fetching latest from origin for local repo: {}", repo_source); + let fetch_output = Command::new("git") + .args(["fetch", "origin"]) + .current_dir(&path) + .output() + .await?; + + if !fetch_output.status.success() { + let stderr = String::from_utf8_lossy(&fetch_output.stderr); + tracing::warn!("Git fetch from origin failed (continuing anyway): {}", stderr); + } else { + tracing::info!("Successfully fetched latest changes from origin for {}", repo_source); + } + } else { + tracing::debug!("Local repo has no origin remote: {}", repo_source); + } + + // Fetch from all remotes (includes any other remotes besides origin) let output = Command::new("git") .args(["fetch", "--all", "--prune"]) .current_dir(&path) @@ -267,9 +296,7 @@ impl WorktreeManager { if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); // Don't fail - repo might not have a remote configured - tracing::debug!("Git fetch for local repo (may not have remote): {}", stderr); - } else { - tracing::info!("Fetched latest changes for {}", repo_source); + tracing::debug!("Git fetch --all for local repo (may not have remote): {}", stderr); } Ok(path) -- cgit v1.2.3