fix(i18n): preserve merge conflicts without runtime

This commit is contained in:
Tianyi Cui
2026-08-09 00:37:46 +08:00
parent 9a4b70cf3b
commit 9c13a62702
12 changed files with 358 additions and 60 deletions
+27 -23
View File
@@ -10,31 +10,35 @@ import {
const args = process.argv.slice(2)
try {
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim()
if (args[0] === '--resolve') {
if (args.length !== 1) throw new Error('--resolve takes no paths; it inspects the unmerged index')
const resolved = resolveTranslationPairingConflicts(root)
if (resolved.length === 0) {
console.log('merge-translation-pairing: no unresolved pairing records')
} else {
for (const path of resolved) console.log(`merge-translation-pairing: resolved ${path}`)
}
if (args[0] === '--probe') {
if (args.length !== 1) throw new Error('--probe takes no other arguments')
} else {
if (args.length !== 4) {
throw new Error('merge-driver mode requires <ancestor> <current> <other> <repository-path>')
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim()
if (args[0] === '--resolve') {
if (args.length !== 1) throw new Error('--resolve takes no paths; it inspects the unmerged index')
const resolved = resolveTranslationPairingConflicts(root)
if (resolved.length === 0) {
console.log('merge-translation-pairing: no unresolved pairing records')
} else {
for (const path of resolved) console.log(`merge-translation-pairing: resolved ${path}`)
}
} else {
if (args.length !== 4) {
throw new Error('merge-driver mode requires <ancestor> <current> <other> <repository-path>')
}
const [ancestorPath, currentPath, otherPath, metaPath] = args
if (ancestorPath === undefined || currentPath === undefined || otherPath === undefined || metaPath === undefined) {
throw new Error('merge-driver arguments are incomplete')
}
const result = mergeTranslationPairingRecords(
root,
metaPath,
readFileSync(ancestorPath, 'utf8'),
readFileSync(currentPath, 'utf8'),
readFileSync(otherPath, 'utf8'),
)
writeFileSync(currentPath, result.record)
}
const [ancestorPath, currentPath, otherPath, metaPath] = args
if (ancestorPath === undefined || currentPath === undefined || otherPath === undefined || metaPath === undefined) {
throw new Error('merge-driver arguments are incomplete')
}
const result = mergeTranslationPairingRecords(
root,
metaPath,
readFileSync(ancestorPath, 'utf8'),
readFileSync(currentPath, 'utf8'),
readFileSync(otherPath, 'utf8'),
)
writeFileSync(currentPath, result.record)
}
} catch (error) {
console.error(`merge-translation-pairing: ${error instanceof Error ? error.message : String(error)}`)