Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): an untracked directory named like the ownership stamp still makes the tree dirty (#6083)

garrytanc1a24923fc44
diff --git a/src/core/persistence/root-metadata.ts b/src/core/persistence/root-metadata.ts
index 94c9061837..5affde2d2c 100644
--- a/src/core/persistence/root-metadata.ts
+++ b/src/core/persistence/root-metadata.ts
@@ -12,11 +12,12 @@ export function isPhysicalRootMetadata(name: string): boolean {
* `git status --porcelain` (v1) output without entries whose every path is
* physical-root metadata, so the stamp gbrain writes does not make a managed
* tree look dirty. A rename or copy keeps its line unless both sides are
- * metadata, and a quoted path never matches an exact metadata name.
+ * metadata, a quoted path never matches an exact metadata name, and an
+ * untracked directory (porcelain's trailing `/`) is never metadata.
*/
export function withoutPhysicalRootMetadata(porcelain: string): string {
return porcelain
.split('\n')
- .filter(line => line.trim() !== '' && !line.slice(3).split(' -> ').every(path => isPhysicalRootMetadata(basename(path.trim()))))
+ .filter(line => line.trim() !== '' && !line.slice(3).split(' -> ').every(path => !path.trim().endsWith('/') && isPhysicalRootMetadata(basename(path.trim()))))
.join('\n');
}
diff --git a/test/persistence-root-metadata.test.ts b/test/persistence-root-metadata.test.ts
index ae8d4f241e..6f3153b717 100644
--- a/test/persistence-root-metadata.test.ts
+++ b/test/persistence-root-metadata.test.ts
@@ -32,6 +32,11 @@ describe('withoutPhysicalRootMetadata', () => {
expect(withoutPhysicalRootMetadata('?? ".gbrain-owner.json "')).toBe('?? ".gbrain-owner.json "');
});
+ test('an untracked directory that happens to carry the stamp name is real content', () => {
+ expect(withoutPhysicalRootMetadata('?? .gbrain-owner.json/\n?? notes/.gbrain-owner.json/\n'))
+ .toBe('?? .gbrain-owner.json/\n?? notes/.gbrain-owner.json/');
+ });
+
test('the physical-root facade re-exports the same predicate', () => {
expect(viaPhysicalRoot).toBe(isPhysicalRootMetadata);
});