@@ -260,25 +260,42 @@ export const namesOfRebaseCommandsThatMakeRebaseExitToPause: EitherRebaseCommand
260260 ( cmd ) => cmd . nameButNeverAlias
261261) ;
262262
263- type BadCommand = {
264- command : string ;
263+ type LineNr = {
264+ /**
265+ * indexed from 0.
266+ * counts comments/empty-lines/etc, see `nthCommand` instead
267+ */
265268 lineNumber : number ;
269+
270+ /**
271+ * indexed from 1.
272+ * counts comments/empty-lines/etc, see `nthCommand` instead
273+ */
274+ humanLineNumber : number ;
275+
276+ /**
277+ * indexed from 0.
278+ * counts only commands
279+ * (both good and bad, though irrelevant, because will error if has bad commands)
280+ */
281+ nthCommand : number ;
282+ } ;
283+
284+ type BadCommand = LineNr & {
285+ command : string ;
266286 fullLine : string ;
267287 reasons : string [ ] ;
268288} ;
269289
270- export type GoodCommandBase = {
290+ export type GoodCommandBase = LineNr & {
271291 commandOrAliasName : EitherRebaseEitherCommandOrAlias ;
272- lineNumber : number ;
273292 fullLine : string ;
274293 rest : string ;
275294 /**
276295 * SHA or branch or label (all commands, except `break`, have >=1)
277296 * TODO: handle >1
278297 */
279298 targets : string [ ] | null ;
280- index : number ;
281-
282299 // commandName: EitherRebaseCommand;
283300} ;
284301export type GoodCommandRegular = GoodCommandBase & {
@@ -317,32 +334,36 @@ export function validate(
317334 return command in allEitherRebaseCommands || command in allEitherRebaseCommandAliases ;
318335 }
319336
320- let previousCommitSHA : string | null ;
337+ let previousCommitSHA : string | null = null ;
338+ let nthCommand : number = - 1 ;
321339 /**
322340 * we're not processing command-by-command, we're processing line-by-line.
323341 */
324- linesOfEditedRebaseTodo . forEach ( ( fullLine , index ) => {
342+ for ( let lineNumber = 0 ; lineNumber < linesOfEditedRebaseTodo . length ; lineNumber ++ ) {
343+ const fullLine : string = linesOfEditedRebaseTodo [ lineNumber ] ;
344+
325345 if ( fullLine . startsWith ( "#" ) ) {
326346 /**
327347 * ignore comments
328348 */
329- return ;
349+ continue ;
330350 }
351+ nthCommand ++ ;
331352
332353 const [ commandOrAliasName , ..._rest ] = fullLine . split ( " " ) ;
333354 const rest = _rest . join ( " " ) ;
334355
335- const lineNumber : number = index + 1 ;
336-
337356 if ( ! commandOrAliasExists ( commandOrAliasName ) ) {
338357 badCommands . push ( {
339358 command : commandOrAliasName ,
359+ nthCommand,
340360 lineNumber,
361+ humanLineNumber : lineNumber + 1 ,
341362 fullLine,
342363 reasons : [ "unrecognized command" ] ,
343364 } ) ;
344365
345- return ;
366+ continue ;
346367 }
347368
348369 const commandName : EitherRebaseCommand =
@@ -357,7 +378,7 @@ export function validate(
357378 const reasonsIfBad : string [ ] = [ ] ;
358379
359380 if ( enforceRequirementsSpecificToStackedRebase ) {
360- if ( index === 0 ) {
381+ if ( nthCommand === 0 ) {
361382 if ( commandName !== "branch-end-initial" ) {
362383 reasonsIfBad . push ( "initial command must be `branch-end-initial`" ) ;
363384 }
@@ -396,15 +417,18 @@ export function validate(
396417 badCommands . push ( {
397418 command : commandName ,
398419 lineNumber,
420+ humanLineNumber : lineNumber + 1 ,
421+ nthCommand,
399422 fullLine,
400423 reasons : reasonsIfBad ,
401424 } ) ;
402425 } else {
403426 goodCommands . push ( {
404427 commandOrAliasName,
405428 targets,
406- index,
407429 lineNumber,
430+ humanLineNumber : lineNumber + 1 ,
431+ nthCommand,
408432 fullLine,
409433 rest,
410434 ...( commandName in regularRebaseCommands
@@ -427,15 +451,15 @@ export function validate(
427451 previousCommitSHA = targets ?. [ 0 ] ?? null ;
428452 }
429453 }
430- } ) ;
454+ }
431455
432456 if ( badCommands . length ) {
433457 throw new Termination (
434458 "\n" +
435459 joinWith ( "\n\n" ) ( [
436460 "found errors in rebase commands:" ,
437461 ...badCommands . map ( ( cmd ) =>
438- bullets ( ` line ${ cmd . lineNumber } : ${ tick ( cmd . command ) } ` , cmd . reasons , " - " )
462+ bullets ( ` line ${ cmd . humanLineNumber } : ${ tick ( cmd . command ) } ` , cmd . reasons , " - " )
439463 ) ,
440464 "to edit & fix, use:" ,
441465 " git-stacked-rebase -e|--edit-todo\n" ,
0 commit comments