Skip to content

Commit 92a3126

Browse files
peterdrierclaude
andcommitted
fix: handle linked-worktree .git layout and render no-op keep as success
- Use `git rev-parse --git-dir` instead of hardcoded `.git/` path for the exclude file, fixing ENOTDIR when repo is a linked worktree. - Render no-op keep cleanup as success instead of misleading "failed" message when there were simply no changes to apply. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 28d3909 commit 92a3126

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

plugins/codex/scripts/lib/git.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ export function createWorktree(repoRoot) {
192192
const worktreesDir = path.join(repoRoot, ".worktrees");
193193
fs.mkdirSync(worktreesDir, { recursive: true });
194194

195-
// Ensure .worktrees/ is excluded from the target repo without modifying tracked files
196-
const excludePath = path.join(repoRoot, ".git", "info", "exclude");
195+
// Ensure .worktrees/ is excluded from the target repo without modifying tracked files.
196+
// Use git rev-parse to resolve the real git dir (handles linked worktrees where .git is a file).
197+
const gitDir = gitChecked(repoRoot, ["rev-parse", "--git-dir"]).stdout.trim();
198+
const excludePath = path.join(gitDir, "info", "exclude");
197199
const excludeContent = fs.existsSync(excludePath) ? fs.readFileSync(excludePath, "utf8") : "";
198200
if (!excludeContent.includes(".worktrees")) {
199201
fs.mkdirSync(path.dirname(excludePath), { recursive: true });

plugins/codex/scripts/lib/render.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ export function renderWorktreeCleanupResult(action, result, session) {
490490
if (action === "keep") {
491491
if (result.applied) {
492492
lines.push(`Applied changes from \`${session.branch}\` and cleaned up.`);
493+
} else if (result.detail === "No changes to apply.") {
494+
lines.push(`No changes to apply. Worktree and branch \`${session.branch}\` cleaned up.`);
493495
} else {
494496
lines.push(`Failed to apply changes: ${result.detail}`);
495497
lines.push("");

0 commit comments

Comments
 (0)