diff --git a/src/cli/commands/sync.ts b/src/cli/commands/sync.ts index da7565d..b9685b4 100644 --- a/src/cli/commands/sync.ts +++ b/src/cli/commands/sync.ts @@ -886,12 +886,28 @@ function showDiff(remote: string, local: string) { let lineCount = 0 const maxLines = 50 const contextLines = 3 + let remoteLine = 1 + let localLine = 1 + let needsHeader = true + + let hunkCount = 0 + + const printHeader = (_rStart: number, lStart: number) => { + if (hunkCount > 0) console.log() + if (lStart > 1) { + console.log(color.cyan(`Line ${lStart}:`)) + lineCount++ + } + needsHeader = false + hunkCount++ + } for (let i = 0; i < changes.length; i++) { const part = changes[i]! const lines = part.value.replace(/\n$/, '').split('\n') if (part.added) { + if (needsHeader) printHeader(remoteLine, localLine) for (const line of lines) { if (lineCount >= maxLines) { console.log(color.gray('... diff truncated')) @@ -900,7 +916,9 @@ function showDiff(remote: string, local: string) { console.log(color.green(`+ ${line}`)) lineCount++ } + localLine += lines.length } else if (part.removed) { + if (needsHeader) printHeader(remoteLine, localLine) for (const line of lines) { if (lineCount >= maxLines) { console.log(color.gray('... diff truncated')) @@ -909,6 +927,7 @@ function showDiff(remote: string, local: string) { console.log(color.red(`- ${line}`)) lineCount++ } + remoteLine += lines.length } else { // Context: show lines near changes const prevHasChange = i > 0 && (changes[i - 1]!.added || changes[i - 1]!.removed) @@ -929,9 +948,11 @@ function showDiff(remote: string, local: string) { if (nextHasChange) { const start = Math.max(0, lines.length - contextLines) if (start > 0) { - console.log(color.gray(' ...')) - lineCount++ + needsHeader = true } + const headerLine = remoteLine + start + const headerLocalLine = localLine + start + if (needsHeader) printHeader(headerLine, headerLocalLine) for (let j = start; j < lines.length; j++) { if (lineCount >= maxLines) { console.log(color.gray('... diff truncated')) @@ -942,7 +963,7 @@ function showDiff(remote: string, local: string) { } } // Show context after previous change - if (prevHasChange) { + if (prevHasChange && !nextHasChange) { const end = Math.min(lines.length, contextLines) for (let j = 0; j < end; j++) { if (lineCount >= maxLines) { @@ -952,11 +973,13 @@ function showDiff(remote: string, local: string) { console.log(color.gray(` ${lines[j]}`)) lineCount++ } - if (end < lines.length && !nextHasChange) { - console.log(color.gray(' ...')) + if (end < lines.length) { + needsHeader = true } } } + remoteLine += lines.length + localLine += lines.length } } }