diff options
| author | soryu <soryu@soryu.co> | 2026-02-20 01:11:13 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-20 01:11:13 +0000 |
| commit | 5f8cb48d153f3ef1480c73a1ac3536219755f7e3 (patch) | |
| tree | 9abe0b6b092740829e24ba61410b9a53cb02b868 | |
| parent | aa974c4888851f10c782e07b9d9bff7a6f1aef15 (diff) | |
| download | soryu-5f8cb48d153f3ef1480c73a1ac3536219755f7e3.tar.gz soryu-5f8cb48d153f3ef1480c73a1ac3536219755f7e3.zip | |
fix: restore start_point logic stripped by pre-commit hook
The previous commit's pre-commit hook removed the start_point
definition block but left the reference, breaking compilation.
Re-add the branch-existence check with default-branch fallback.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rw-r--r-- | makima/src/daemon/worktree/manager.rs | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/makima/src/daemon/worktree/manager.rs b/makima/src/daemon/worktree/manager.rs index ea26767..2caa86a 100644 --- a/makima/src/daemon/worktree/manager.rs +++ b/makima/src/daemon/worktree/manager.rs @@ -491,16 +491,81 @@ impl WorktreeManager { .output() .await; - // Create the worktree with a new branch based on the local base_branch - let output = Command::new("git") + // Prefer origin/{base_branch} to get latest remote state. + // If neither origin/{base_branch} nor {base_branch} exist (e.g. PR branch + // was deleted after merge), fall back to the repo's default branch. + let origin_ref = format!("origin/{}", base_branch); + let has_origin_ref = Command::new("git") .args([ - "worktree", - "add", - "-b", - &branch_name, + "rev-parse", + "--verify", + &format!("refs/remotes/{}", origin_ref), ]) + .current_dir(source_repo) + .output() + .await + .map(|o| o.status.success()) + .unwrap_or(false); + + let has_local_ref = if !has_origin_ref { + Command::new("git") + .args([ + "rev-parse", + "--verify", + &format!("refs/heads/{}", base_branch), + ]) + .current_dir(source_repo) + .output() + .await + .map(|o| o.status.success()) + .unwrap_or(false) + } else { + false // don't need to check — we already have origin ref + }; + + let start_point: String = if has_origin_ref { + origin_ref + } else if has_local_ref { + base_branch.to_string() + } else { + // Branch doesn't exist (likely deleted after PR merge) — use default branch + tracing::warn!( + task_id = %task_id, + base_branch = %base_branch, + "Base branch ref not found, falling back to default branch" + ); + let default_branch = + self.detect_default_branch(source_repo).await?; + let default_origin = format!("origin/{}", default_branch); + let has_default_origin = Command::new("git") + .args([ + "rev-parse", + "--verify", + &format!("refs/remotes/{}", default_origin), + ]) + .current_dir(source_repo) + .output() + .await + .map(|o| o.status.success()) + .unwrap_or(false); + if has_default_origin { + default_origin + } else { + default_branch + } + }; + + tracing::info!( + task_id = %task_id, + start_point = %start_point, + "Using start point for new worktree branch" + ); + + // Create the worktree with a new branch based on the start point + let output = Command::new("git") + .args(["worktree", "add", "-b", &branch_name]) .arg(&worktree_path) - .arg(start_point) + .arg(&start_point) .current_dir(source_repo) .output() .await?; |
