Skip to content

Commit 36a945e

Browse files
feat: fetch latest remote before creating worktrees (#100)
Worktrees were being created from the local default branch ref, which could be behind the remote. Now fetches origin/<defaultBranch> before worktree creation and uses the remote tracking ref as the start-point, ensuring worktrees always start from the latest remote code without mutating the main repo's working tree. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4d41a02 commit 36a945e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/issues/pipeline.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,19 @@ export async function runIssuePipeline(
864864
if (!existsSync(worktreeDir)) {
865865
mkdirSync(join(repo.localRepoPath, ".claude", "worktrees"), { recursive: true });
866866

867+
// Fetch latest default branch so worktree starts from current remote code
867868
try {
868-
execFileSync("git", ["worktree", "add", worktreeDir, "-b", branchName, repo.defaultBranch], {
869+
execFileSync("git", ["fetch", "origin", repo.defaultBranch], {
870+
cwd: repo.localRepoPath, stdio: "ignore", timeout: 30_000,
871+
});
872+
} catch {
873+
// Non-fatal: proceed with last-known origin/<defaultBranch> or local state.
874+
// Common reasons: offline, no remote named 'origin', non-default refspec.
875+
console.warn(`[pipeline] Could not fetch latest ${repo.defaultBranch} — will use last-known origin/${repo.defaultBranch}`);
876+
}
877+
878+
try {
879+
execFileSync("git", ["worktree", "add", worktreeDir, "-b", branchName, `origin/${repo.defaultBranch}`], {
869880
cwd: repo.localRepoPath, stdio: "ignore",
870881
});
871882
} catch {

0 commit comments

Comments
 (0)