Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: parse quoted git status paths (#12573)

[._.]/ Adam Eivyc698a0b9a82f
diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.js
index 81bea75fbf..8002899ddf 100644
--- a/server/services/worktreeManager.js
+++ b/server/services/worktreeManager.js
@@ -531,15 +531,59 @@ async function enforceUpstreamOrUndoAdd(sourceWorkspace, branchName, worktreePat
*/
export function classifyWorktreeDirt(porcelain, { ignoredPaths = [] } = {}) {
const ignored = [...AGENT_SCRATCH_PATHS, ...ignoredPaths];
- const toPath = (line) => line.replace(/^\s*\S+\s+/, '').split(' -> ').pop();
+ // Git's porcelain v1 output C-quotes paths with spaces and several other
+ // characters. Decode those paths before comparing them with scratch roots or
+ // lockfile names. Octal escapes represent bytes, so collect them as bytes and
+ // decode UTF-8 only after the whole quoted path has been read.
+ const unquoteGitPath = (path) => {
+ if (!path.startsWith('"') || !path.endsWith('"')) return path;
+ const bytes = [];
+ for (let i = 1; i < path.length - 1; i += 1) {
+ const char = path[i];
+ if (char !== '\\') {
+ bytes.push(...Buffer.from(char));
+ continue;
+ }
+ const escaped = path[++i];
+ if (/[0-7]/.test(escaped || '')) {
+ const octal = path.slice(i, i + 3);
+ if (!/^[0-7]{3}$/.test(octal)) {
+ bytes.push(...Buffer.from(`\\${escaped}`));
+ continue;
+ }
+ bytes.push(parseInt(octal, 8));
+ i += 2;
+ continue;
+ }
+ const controls = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
+ if (Object.hasOwn(controls, escaped)) bytes.push(controls[escaped]);
+ else bytes.push(...Buffer.from(escaped || ''));
+ }
+ return Buffer.from(bytes).toString('utf8');
+ };
+ const splitRename = (path) => {
+ let quoted = false;
+ let escaped = false;
+ for (let i = 0; i <= path.length - 4; i += 1) {
+ const char = path[i];
+ if (escaped) { escaped = false; continue; }
+ if (quoted && char === '\\') { escaped = true; continue; }
+ if (char === '"') { quoted = !quoted; continue; }
+ if (!quoted && path.startsWith(' -> ', i)) return [path.slice(0, i), path.slice(i + 4)];
+ }
+ return [path];
+ };
+ const toPath = (line) => {
+ const statusless = line.replace(/^\s*\S+\s+/, '');
+ return splitRename(statusless).map(unquoteGitPath).at(-1);
+ };
const lines = (porcelain || '').split('\n')
- .map(l => l.trim())
- .filter(Boolean)
+ .filter(l => l.trim())
.filter(line => !matchesScratchRoot(toPath(line), ignored));
if (lines.length === 0) {
return { clean: true, lockfileOnly: false, lockfilePaths: [], untrackedLockfilePaths: [], realChangePaths: [], hasRealChanges: false };
}
- const isLockfile = (line) => AUTO_GENERATED_LOCKFILES.some(f => line.endsWith(f));
+ const isLockfile = (line) => AUTO_GENERATED_LOCKFILES.some(f => toPath(line).endsWith(f));
// `R old -> new` (rename) names two paths; the post-rename path is the one
// that exists on disk and the one a diff against the default branch reports.
const lockfileLines = lines.filter(isLockfile);
diff --git a/server/services/worktreeManager.test.js b/server/services/worktreeManager.test.js
index deeaa1a9cf..7ca9edba1d 100644
--- a/server/services/worktreeManager.test.js
+++ b/server/services/worktreeManager.test.js
@@ -236,6 +236,17 @@ describe('classifyWorktreeDirt (real exported helper)', () => {
expect(r.lockfilePaths).toEqual(['package-lock.json', 'client/package-lock.json']);
});
+ it('decodes Git-quoted paths before lockfile and scratch classification', () => {
+ const lockfile = classifyWorktreeDirt(' M "my app/package-lock.json"\n');
+ expect(lockfile.lockfileOnly).toBe(true);
+ expect(lockfile.lockfilePaths).toEqual(['my app/package-lock.json']);
+
+ expect(classifyWorktreeDirt('?? ".portos-public-review/"').clean).toBe(true);
+ expect(classifyWorktreeDirt('?? "PORTOS_PUBLIC_REVIEW_INPUT.json"').clean).toBe(true);
+ expect(classifyWorktreeDirt('?? "caf\\303\\251/package-lock.json"').lockfilePaths)
+ .toEqual(['café/package-lock.json']);
+ });
+
it('treats mixed lockfile + real changes as real changes', () => {
const r = classifyWorktreeDirt(' M package-lock.json\n M src/app.js');
expect(r.lockfileOnly).toBe(false);
@@ -251,6 +262,11 @@ describe('classifyWorktreeDirt (real exported helper)', () => {
expect(r.realChangePaths).not.toContain('package-lock.json');
});
+ it('splits quoted rename paths without treating a literal arrow as the separator', () => {
+ const r = classifyWorktreeDirt('R "a -> b/x" -> "a b/y"');
+ expect(r.realChangePaths).toEqual(['a b/y']);
+ });
+
it('handles a trimmed first line (no leading status space)', () => {
const r = classifyWorktreeDirt('M yarn.lock');
expect(r.lockfileOnly).toBe(true);