* A parser to read and emit rebase progress from Git `stderr`
| 282 | * A parser to read and emit rebase progress from Git `stderr` |
| 283 | */ |
| 284 | class GitRebaseParser { |
| 285 | public constructor(private readonly commits: ReadonlyArray<CommitOneLine>) {} |
| 286 | |
| 287 | public parse(line: string): IMultiCommitOperationProgress | null { |
| 288 | const match = rebasingRe.exec(line) |
| 289 | if (match === null || match.length !== 3) { |
| 290 | // Git will sometimes emit other output (for example, when it tries to |
| 291 | // resolve conflicts) and this does not match the expected output |
| 292 | return null |
| 293 | } |
| 294 | |
| 295 | const rebasedCommitCount = parseInt(match[1], 10) |
| 296 | const totalCommitCount = parseInt(match[2], 10) |
| 297 | |
| 298 | if (isNaN(rebasedCommitCount) || isNaN(totalCommitCount)) { |
| 299 | return null |
| 300 | } |
| 301 | |
| 302 | const currentCommitSummary = |
| 303 | this.commits[rebasedCommitCount - 1]?.summary ?? '' |
| 304 | |
| 305 | const progress = rebasedCommitCount / totalCommitCount |
| 306 | const value = formatRebaseValue(progress) |
| 307 | |
| 308 | return { |
| 309 | kind: 'multiCommitOperation', |
| 310 | value, |
| 311 | position: rebasedCommitCount, |
| 312 | totalCommitCount: totalCommitCount, |
| 313 | currentCommitSummary, |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | function configureOptionsForRebase<T extends IGitExecutionOptions>( |
| 319 | options: T, |
nothing calls this directly
no outgoing calls
no test coverage detected