fix: mirror sync files before commit
This commit is contained in:
+18
-5
@@ -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) {
|
||||
|
||||
+5
-4
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user