-
Notifications
You must be signed in to change notification settings - Fork 0
fix(worktree): skip rescue for noise-only worktrees #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,13 @@ import { createLogger } from './logger.js'; | |
|
|
||
| const log = createLogger('worktree'); | ||
|
|
||
| /** | ||
| * Files that are not meaningful work — rescue should skip if these are the only changes. | ||
| * Matched via exact path from `git diff --cached --name-only` (root-relative). | ||
| * Only root-level files are supported; subdirectory paths would need `subdir/file` entries. | ||
| */ | ||
| const RESCUE_NOISE_FILES = new Set(['.mitzo-session']); | ||
|
|
||
| /** | ||
| * Detect the default branch of a repo (e.g. 'main' or 'master'). | ||
| * Prefers origin/HEAD (remote truth) since session worktrees should branch | ||
|
|
@@ -463,6 +470,28 @@ export function rescueDirtyWorktree( | |
| return { success: false, error: err instanceof Error ? err.message : String(err) }; | ||
| } | ||
|
|
||
| // 1b. Check if staged changes contain meaningful work (not just noise markers) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 unsafe_assumptions: The
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 style: The noise-file check step is labeled '1b' in test comments but has no step comment in the actual code (unlike steps 1, 2, 3, 4 which have numbered comments). Adding a consistent step label would improve readability. |
||
| try { | ||
| const staged = execFileSync('git', ['-C', worktreePath, 'diff', '--cached', '--name-only'], { | ||
| encoding: 'utf-8', | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| timeout: WORKTREE_GIT_TIMEOUT_MS, | ||
| }).trim(); | ||
| const files = staged ? staged.split('\n') : []; | ||
| if (files.length === 0 || files.every((f) => RESCUE_NOISE_FILES.has(f))) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bugs: Noise-only worktrees become permanently stuck. |
||
| log.info('rescue skipped — only noise files changed', { wtId, files }); | ||
| // Unstage so the worktree can be cleaned up without leaving staged changes | ||
| try { | ||
| execFileSync('git', ['-C', worktreePath, 'reset', 'HEAD'], gitOpts); | ||
| } catch { | ||
| // Non-fatal — worktree is about to be removed anyway | ||
| } | ||
| return { success: false, error: 'no meaningful changes to rescue' }; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bugs: When rescue returns |
||
| } | ||
| } catch { | ||
| // If we can't inspect staged files, proceed with the rescue anyway — safer than skipping | ||
| } | ||
|
|
||
| try { | ||
| // 2. Commit | ||
| execFileSync( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 style: Three new test cases have comments saying 'Step 1: git add -A' (lines 277, 296, 317) but the implementation at worktree.ts:468 uses
git add -u. The distinction matters (tracked-only vs all files). Inaccurate test comments can mislead future maintainers about what the code actually does.[fixable]