Skip to content

Commit

Permalink
fix: harden "stg rebase -i" against patches with milti-line subjects
Browse files Browse the repository at this point in the history
I have a stgit stack that is very old (I started it more than 10 years
ago), so it has all kinds of WIP patches that I started and then did
not quite finish. In several of them I have malformed patch subjects,
such as multi-line titles:

$ git show -1 --pretty=%B
subsystem: fix driver
certain change

This breaks "stg rebase -i" because it expects to have one line per
patch in the rebase template, but in this case subject spills
over to the next line which rebase mistakes for an instruction:

error: unknown instruction action `certain`

Fix this my replacing new lines and line feeds in the subject with
spaces.

Signed-off-by: Dmitry Torokhov <dtor@google.com>
  • Loading branch information
dtor authored and jpgrayson committed Jul 20, 2024
1 parent 2c8d707 commit 90f3d93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cmd/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ fn make_instructions_template(stack: &Stack, previously_applied: &[PatchName]) -
let subject = commit
.message()
.map(|message_ref| message_ref.title.to_str_lossy())
.unwrap_or_default();
.unwrap_or_default()
.replace(['\r', '\n'], " ")
.trim()
.to_owned();
writeln!(template, "keep {patchname:name_width$} # {subject}").unwrap();
}
if !found_apply_boundary {
Expand Down
9 changes: 9 additions & 0 deletions t/t2203-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,13 @@ test_expect_success 'No patches exits early' '
stg rebase --interactive
'

test_expect_success 'Patches with multi-line subject' '
printf "p0: line 1\nline 2\n" | stg new -f - p0 &&
printf "p1: line 1\nline 2\n" | stg new -f - p1 &&
test_set_editor cat &&
test_when_finished test_set_editor false &&
stg rebase --interactive &&
test "$(stg series --applied -c)" = "2"
'

test_done

0 comments on commit 90f3d93

Please sign in to comment.