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.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/makima/src/daemon/worktree/manager.rs b/makima/src/daemon/worktree/manager.rs
index 5df9a73..c27bcf6 100644
--- a/makima/src/daemon/worktree/manager.rs
+++ b/makima/src/daemon/worktree/manager.rs
@@ -484,7 +484,29 @@ impl WorktreeManager {
"Creating worktree with new branch"
);
- // Create the worktree with a new branch based on the local base_branch
+ // Prefer origin/{base_branch} to get latest remote state
+ let origin_ref = format!("origin/{}", base_branch);
+ let has_origin_ref = Command::new("git")
+ .args(["rev-parse", "--verify", &format!("refs/remotes/{}", origin_ref)])
+ .current_dir(source_repo)
+ .output()
+ .await
+ .map(|o| o.status.success())
+ .unwrap_or(false);
+
+ let start_point = if has_origin_ref {
+ origin_ref.as_str()
+ } else {
+ base_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",
@@ -493,7 +515,7 @@ impl WorktreeManager {
&branch_name,
])
.arg(&worktree_path)
- .arg(base_branch)
+ .arg(start_point)
.current_dir(source_repo)
.output()
.await?;