Bug fix for multi-line commit messages with dolt rebase

This commit is contained in:
Jason Fulghum
2025-10-02 10:21:21 -07:00
parent cc7fa424f2
commit eb7bd16246
4 changed files with 81 additions and 0 deletions

View File

@@ -88,6 +88,9 @@ jobs:
- name: Install expect
if: matrix.os == 'ubuntu-22.04'
run: sudo apt-get install -y expect
- name: Install pcre2grep
if: matrix.os == 'ubuntu-22.04'
run: sudo apt-get install -y pcre2-utils
- name: Install Maven
working-directory: ./.ci_bin
run: |

View File

@@ -266,6 +266,10 @@ func buildInitialRebaseMsg(sqlCtx *sql.Context, queryist cli.Queryist, rebaseBra
if !ok {
return "", fmt.Errorf("unexpected type for commit_message; expected string, found %T", commitMessage)
}
// Match Git's behavior and filter out newlines
commitMessage = strings.Replace(commitMessage, "\n", " ", -1)
buffer.WriteString(fmt.Sprintf("%s %s %s\n", action, commitHash, commitMessage))
}
buffer.WriteString("\n")

View File

@@ -1611,6 +1611,47 @@ var DoltRebaseScriptTests = []queries.ScriptTest{
},
},
},
{
Name: "dolt_rebase: handles multi-line commit messages",
SetUpScript: []string{
`CALL dolt_commit('--allow-empty', '-m', 'empty commit 1');`,
`CALL dolt_commit('--allow-empty', '-m', 'empty
commit
2');`,
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT message FROM dolt_log LIMIT 1;",
Expected: []sql.Row{
{"empty \ncommit \n2"},
},
},
{
Query: "CALL dolt_rebase('-i', '--empty=keep', 'HEAD~1');",
Expected: []sql.Row{
{0, "interactive rebase started on branch dolt_rebase_main; adjust the rebase plan in the dolt_rebase table, then continue rebasing by calling dolt_rebase('--continue')"},
},
},
{
Query: "SELECT * from dolt_rebase;",
Expected: []sql.Row{
{"1", "pick", doltCommit, "empty \ncommit \n2"},
},
},
{
Query: "CALL dolt_rebase('--continue');",
Expected: []sql.Row{
{0, "Successfully rebased and updated refs/heads/main"},
},
},
{
Query: "SELECT message FROM dolt_log LIMIT 1;",
Expected: []sql.Row{
{"empty \ncommit \n2"},
},
},
},
},
}
var DoltRebaseMultiSessionScriptTests = []queries.ScriptTest{

View File

@@ -21,9 +21,15 @@ teardown() {
teardown_common
}
# sets up the EDITOR env var with a script that takes the input file from
# the process invoking the editor and copies it to the editor-input.txt
# file for tests to check, and then copies the file specifeid as an argument
# to this function, as the output for the editor, sent back to the process
# that invoked the editor.
setupCustomEditorScript() {
touch rebaseScript.sh
echo "#!/bin/bash" >> rebaseScript.sh
echo "cp \$1 editor-input.txt" >> rebaseScript.sh
if [ $# -eq 1 ]; then
echo "mv $1 \$1" >> rebaseScript.sh
fi
@@ -131,6 +137,33 @@ setupCustomEditorScript() {
[[ "$output" =~ "main commit 2" ]] || false
}
# bats test_tags=no_lambda
# skip bats on lambda, since we don't have the pcre2grep utility there
@test "rebase: multi-line commit messages" {
setupCustomEditorScript
# Create a multi-line commit message
dolt checkout b1
dolt commit --allow-empty -m "multi
line
commit
message"
# Run rebase (with the default plan, custom editor makes no changes)
run dolt rebase --empty=keep -i main
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully rebased and updated refs/heads/b1" ]] || false
# Assert that the newlines were removed in the rebase plan editor
grep "multi line commit message" editor-input.txt
# Assert that the commit log still shows the multi-line message
run dolt log -n1
[ "$status" -eq 0 ]
echo "$output" > tmp.out
pcre2grep -nM "multi\s*\R+\s*line\s*\R+\s*commit\s*\R+\s*message" tmp.out
}
@test "rebase: failed rebase will abort and clean up" {
setupCustomEditorScript "invalidRebasePlan.txt"
dolt checkout b1