From c70a81898622def50656ef1156882363ada691ae Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 15 May 2026 03:09:54 +0000 Subject: [PATCH] fix: mirror sync files before commit --- app/git.js | 23 ++++++++++++++++++----- app/git.test.js | 9 +++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/git.js b/app/git.js index 140420d..b21c3b5 100644 --- a/app/git.js +++ b/app/git.js @@ -65,19 +65,32 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync) run(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); run(['config', 'user.name', 'AI Review Bot'], repoDir); - // Always copy source files over the repo copy so skill files stay in sync. + const existingSyncPaths = []; + const missingSyncPaths = []; + + // Mirror sync files from workspace into the repo copy. for (const relPath of SYNC_PATHS) { const src = path.join(workspace, relPath); const dest = path.join(repoDir, relPath); - if (!fs.existsSync(src)) continue; - fs.mkdirSync(path.dirname(dest), { recursive: true }); - fs.copyFileSync(src, dest); + if (fs.existsSync(src)) { + fs.mkdirSync(path.dirname(dest), { recursive: true }); + fs.copyFileSync(src, dest); + existingSyncPaths.push(relPath); + continue; + } + + if (fs.existsSync(dest)) { + fs.rmSync(dest, { force: true }); + } + missingSyncPaths.push(relPath); } - const existingSyncPaths = SYNC_PATHS.filter(relPath => fs.existsSync(path.join(repoDir, relPath))); if (existingSyncPaths.length > 0) { run(['add', ...existingSyncPaths], repoDir); } + if (missingSyncPaths.length > 0) { + run(['rm', '--cached', '--ignore-unmatch', '--', ...missingSyncPaths], repoDir); + } const status = run(['status', '--porcelain'], repoDir); if (!status) { diff --git a/app/git.test.js b/app/git.test.js index c9ab8e2..9807d01 100644 --- a/app/git.test.js +++ b/app/git.test.js @@ -101,7 +101,7 @@ describe('commitAndPush', () => { assert.ok(!addCall.args.includes('README.md')); }); - it('does not add missing sync paths', async () => { + it('removes missing sync paths from the repo copy', async () => { const missingPath = path.join(workspace, '.amazonq/rules/triage-findings.md'); fs.rmSync(missingPath, { force: true }); fs.rmSync(path.join(workspace, 'repo', '.amazonq/rules/triage-findings.md'), { force: true }); @@ -109,9 +109,10 @@ describe('commitAndPush', () => { await commitAndPush(workspace, path.join(workspace, 'repo'), spawn); - const addCall = spawn.calls.find(c => c.args[0] === 'add'); - assert.ok(addCall, 'expected git add to run'); - assert.ok(!addCall.args.includes('.amazonq/rules/triage-findings.md')); + const rmCall = spawn.calls.find(c => c.args[0] === 'rm'); + assert.ok(rmCall, 'expected git rm to run'); + assert.ok(rmCall.args.includes('.amazonq/rules/triage-findings.md')); + assert.equal(fs.existsSync(path.join(workspace, 'repo', '.amazonq/rules/triage-findings.md')), false); }); it('overwrites existing repo copies with workspace files', async () => {