- Skills engine uses <project-root>/tmp/skills for merge/update temp files - Scripts and Telegram voice downloads avoid system /tmp - Add formatSnapshotStamp() for DD.mmm.YYYY-HHMM naming --- Build: pass | Tests: pass — 603 passed (44 files) --- Build: pass | Tests: pass — Tests 603 passed (603)
36 lines
1,000 B
TypeScript
36 lines
1,000 B
TypeScript
import { execFileSync } from 'child_process';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
import { MergeResult } from './types.js';
|
|
|
|
export function isGitRepo(): boolean {
|
|
return fs.existsSync(path.join(process.cwd(), '.git'));
|
|
}
|
|
|
|
/**
|
|
* Run git merge-file to three-way merge files.
|
|
* Modifies currentPath in-place.
|
|
* Returns { clean: true, exitCode: 0 } on clean merge,
|
|
* { clean: false, exitCode: N } on conflict (N = number of conflicts).
|
|
*/
|
|
export function mergeFile(
|
|
currentPath: string,
|
|
basePath: string,
|
|
skillPath: string,
|
|
): MergeResult {
|
|
try {
|
|
execFileSync('git', ['merge-file', currentPath, basePath, skillPath], {
|
|
stdio: 'pipe',
|
|
});
|
|
return { clean: true, exitCode: 0 };
|
|
} catch (err: any) {
|
|
const exitCode = err.status ?? 1;
|
|
if (exitCode > 0) {
|
|
// Positive exit code = number of conflicts
|
|
return { clean: false, exitCode };
|
|
}
|
|
// Negative exit code = error
|
|
throw new Error(`git merge-file failed: ${err.message}`);
|
|
}
|
|
}
|