clawdie-ai/skills-engine/merge.ts
Clawdie AI a2639162a3 fix(tmp): keep temp files under project tmp/ (Sam & Codex)
- 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)
2026-04-03 09:37:42 +00:00

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}`);
}
}