diff options
| author | soryu <soryu@soryu.co> | 2026-01-24 12:35:24 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-24 12:35:24 +0000 |
| commit | df774a06324954b9c90497f83eca44279b70f6d5 (patch) | |
| tree | 3dad94726d9f94467106f302172beb48d56409d1 | |
| parent | 579c983d3efb8f1414ffb45b9e031f741cce5f76 (diff) | |
| download | soryu-df774a06324954b9c90497f83eca44279b70f6d5.tar.gz soryu-df774a06324954b9c90497f83eca44279b70f6d5.zip | |
Reclone if can't find repository
| -rw-r--r-- | makima/src/daemon/worktree/manager.rs | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/makima/src/daemon/worktree/manager.rs b/makima/src/daemon/worktree/manager.rs index 04cb307..fa8a9de 100644 --- a/makima/src/daemon/worktree/manager.rs +++ b/makima/src/daemon/worktree/manager.rs @@ -286,34 +286,56 @@ impl WorktreeManager { tokio::fs::create_dir_all(&self.repos_dir).await?; if repo_path.exists() { - // Fetch latest changes - tracing::info!("Fetching updates for existing repo: {}", repo_name); - let output = Command::new("git") - .args(["fetch", "--all", "--prune"]) + // Verify this is actually a git repository before trying to fetch + let is_git_repo = Command::new("git") + .args(["rev-parse", "--is-bare-repository"]) .current_dir(&repo_path) .output() - .await?; + .await + .map(|o| o.status.success()) + .unwrap_or(false); - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); - tracing::warn!("Git fetch warning: {}", stderr); - // Don't fail on fetch errors, repo might still be usable - } - } else { - // Clone the repository - tracing::info!("Cloning repository: {} -> {}", url, repo_path.display()); - let output = Command::new("git") - .args(["clone", "--bare", url]) - .arg(&repo_path) - .output() - .await?; + if !is_git_repo { + // Directory exists but is not a git repository - remove and re-clone + tracing::warn!( + "Directory {} exists but is not a git repository, removing and re-cloning", + repo_path.display() + ); + tokio::fs::remove_dir_all(&repo_path).await?; - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); - return Err(WorktreeError::CloneFailed(stderr.to_string())); + // Fall through to clone below + } else { + // Fetch latest changes + tracing::info!("Fetching updates for existing repo: {}", repo_name); + let output = Command::new("git") + .args(["fetch", "--all", "--prune"]) + .current_dir(&repo_path) + .output() + .await?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + tracing::warn!("Git fetch warning: {}", stderr); + // Don't fail on fetch errors, repo might still be usable + } + + return Ok(repo_path); } } + // Clone the repository + tracing::info!("Cloning repository: {} -> {}", url, repo_path.display()); + let output = Command::new("git") + .args(["clone", "--bare", url]) + .arg(&repo_path) + .output() + .await?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + return Err(WorktreeError::CloneFailed(stderr.to_string())); + } + Ok(repo_path) } |
