Skip to content

Fix "part N of M" numbering in CLI stacked-PR footers#14152

Open
ameyypawar wants to merge 1 commit into
gitbutlerapp:masterfrom
ameyypawar:fix/stacked-pr-footer-numbering
Open

Fix "part N of M" numbering in CLI stacked-PR footers#14152
ameyypawar wants to merge 1 commit into
gitbutlerapp:masterfrom
ameyypawar:fix/stacked-pr-footer-numbering

Conversation

@ameyypawar

Copy link
Copy Markdown

Fixes #13362

Problem

In stacked-PR description footers, the <kbd> labels number the stack base = 1 … top = M, but the "part N of M" text used the opposite convention — so the base PR showed "part 3 of 3" next to its <kbd>&nbsp;1&nbsp;</kbd> label, and the top PR showed "part 1 of 3" next to <kbd>&nbsp;3&nbsp;</kbd>. This was reported (and reproduced by others) as CLI-only.

Root cause

There are two footer generators:

  • CLI / backend: crates/but-forge/src/review.rs generate_footer
  • Desktop GUI: apps/desktop/src/lib/forge/shared/prFooter.ts generateFooter

In the Rust generator, all_pr_numbers is ordered base→top and the <kbd> loop iterates .rev() (so labels are correct: base = 1). But nth was computed as stack_length - stack_index, which is the inverse of the label — hence the contradiction.

The desktop GUI goes through the TypeScript generator (ReviewCreation.svelte and the drag handlers import updatePrDescriptionTables / updateStackPrs from prFooter.ts), which orders the list top→base and already renders correctly. That's why this only manifested on the CLI.

Fix

One line in review.rs: number nth = stack_index + 1 so "part N" agrees with the <kbd> label at every position (base → 1, top → M). The desktop prFooter.ts generator is intentionally left unchanged — it is already correct, and as @Byron noted on #13363 the GUI renders as expected.

Tests

Verified locally: cargo test -p but-forge footer → 11/11 pass; reverting the one-line change fails exactly those 3 tests. clippy and fmt clean.

Relation to #13363

#13363 targets the same issue but also rewrites the desktop prFooter.ts generator (changing its numbering and reversing its loop). Since the desktop generator is already correct, this PR keeps the change scoped to the Rust/CLI path where the bug actually lives, avoiding a regression to the GUI footer.

The CLI's stacked-PR footer numbered "part N of M" as
`stack_length - stack_index`, the inverse of the `<kbd>` stack labels it
prints alongside (base = 1, top = M). Because `all_pr_numbers` is ordered
base-to-top, the base PR showed "part M of M" next to its `<kbd> 1 </kbd>`
label and the top PR showed "part 1 of M" next to `<kbd> M </kbd>`.

Number "part N" as `stack_index + 1` so it agrees with the label. This
touches only the Rust footer used by the `but` CLI; the desktop GUI uses
the separate TypeScript generator (apps/desktop/src/lib/forge/shared/
prFooter.ts), which orders top-to-base and already renders correctly, so
it is intentionally left unchanged.

Adds "part N of M" assertions to the base/top footer tests (idea from gitbutlerapp#13363).

Fixes gitbutlerapp#13362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Butler CLI - Stacked PR footer: "part N of M" numbering is inconsistent with <kbd> labels

1 participant