Fix #519 by manually creating the patch when github doesn't give it

This commit is contained in:
Misode
2024-10-04 19:02:53 +02:00
parent 7757dbcac3
commit 91f61b3c36
4 changed files with 71 additions and 24 deletions

View File

@@ -562,6 +562,11 @@ export function parseGitPatch(patch: string) {
let after = 1
for (let i = 0; i < source.length; i += 1) {
const line = source[i]
if (line.startsWith('Index: ') || line.startsWith('===')
|| line.startsWith('---') || line.startsWith('+++')
|| line.startsWith('\\') || line.length === 0) {
continue
}
if (line.startsWith('@')) {
const match = line.match(/^@@ -(\d+)(?:,(?:\d+))? \+(\d+)(?:,(?:\d+))? @@/)
if (!match) throw new Error(`Invalid patch pattern at line ${i+1}: ${line}`)
@@ -578,8 +583,8 @@ export function parseGitPatch(patch: string) {
} else if (line.startsWith('-')) {
result.push({ line, before })
before += 1
} else if (!line.startsWith('\\')) {
throw new Error(`Invalid patch, got ${line.charAt(0)} at line ${i+1}`)
} else {
throw new Error(`Invalid patch, got '${line.charAt(0)}' at line ${i+1}`)
}
}
return result