summaryrefslogtreecommitdiff
path: root/makima/src/daemon/worktree/manager.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/daemon/worktree/manager.rs')
-rw-r--r--makima/src/daemon/worktree/manager.rs64
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)
}