1
0
mirror of https://github.com/git/git synced 2024-06-30 22:54:27 +00:00
git/t/t3434-rebase-i18n.sh
Phillip Wood a6c2654f83 rebase -m: fix --signoff with conflicts
When rebasing with "--signoff" the commit created by "rebase --continue"
after resolving conflicts or editing a commit fails to add the
"Signed-off-by:" trailer. This happens because the message from the
original commit is reused instead of the one that would have been used
if the sequencer had not stopped for the user interaction. The correct
message is stored in ctx->message and so with a couple of exceptions
this is written to rebase_path_message() when stopping for user
interaction instead. The exceptions are (i) "fixup" and "squash"
commands where the file is written by error_failed_squash() and (ii)
"edit" commands that are fast-forwarded where the original message is
still reused. The latter is safe because "--signoff" will never
fast-forward.

Note this introduces a change in behavior as the message file now
contains conflict comments. This is safe because commit_staged_changes()
passes an explicit cleanup flag when not editing the message and when
the message is being edited it will be cleaned up automatically. This
means user now sees the same message comments in editor with "rebase
--continue" as they would if they ran "git commit" themselves before
continuing the rebase. It also matches the behavior of "git
cherry-pick", "git merge" etc. which all list the files with merge
conflicts.

The tests are extended to check that all commits made after continuing a
rebase have a "Signed-off-by:" trailer. Sadly there are a couple of
leaks in apply.c which I've not been able to track down that mean this
test file is no-longer leak free when testing "git rebase --apply
--signoff" with conflicts.

Reported-by: David Bimmler <david.bimmler@isovalent.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-04-18 13:33:41 -07:00

88 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright (c) 2019 Doan Tran Cong Danh
#
test_description='rebase with changing encoding
Initial setup:
1 - 2 main
\
3 - 4 first
\
5 - 6 second
'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
compare_msg () {
iconv -f "$2" -t "$3" "$TEST_DIRECTORY/t3434/$1" >expect &&
git cat-file commit HEAD >raw &&
sed "1,/^$/d" raw >actual &&
test_cmp expect actual
}
test_expect_success setup '
test_commit one &&
git branch first &&
test_commit two &&
git switch first &&
test_commit three &&
git branch second &&
test_commit four &&
git switch second &&
test_commit five &&
test_commit six
'
test_expect_success 'rebase --rebase-merges update encoding eucJP to UTF-8' '
git switch -c merge-eucJP-UTF-8 first &&
git config i18n.commitencoding eucJP &&
git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
git config i18n.commitencoding UTF-8 &&
git rebase --rebase-merges main &&
compare_msg eucJP.txt eucJP UTF-8
'
test_expect_success 'rebase --rebase-merges update encoding eucJP to ISO-2022-JP' '
git switch -c merge-eucJP-ISO-2022-JP first &&
git config i18n.commitencoding eucJP &&
git merge -F "$TEST_DIRECTORY/t3434/eucJP.txt" second &&
git config i18n.commitencoding ISO-2022-JP &&
git rebase --rebase-merges main &&
compare_msg eucJP.txt eucJP ISO-2022-JP
'
test_rebase_continue_update_encode () {
old=$1
new=$2
msgfile=$3
test_expect_success "rebase --continue update from $old to $new" '
(git rebase --abort || : abort current git-rebase failure) &&
git switch -c conflict-$old-$new one &&
echo for-conflict >two.t &&
git add two.t &&
git config i18n.commitencoding $old &&
git commit -F "$TEST_DIRECTORY/t3434/$msgfile" &&
git config i18n.commitencoding $new &&
test_must_fail git rebase -m main &&
test -f .git/rebase-merge/message &&
git stripspace -s <.git/rebase-merge/message >two.t &&
git add two.t &&
git rebase --continue &&
compare_msg $msgfile $old $new &&
: git-commit assume invalid utf-8 is latin1 &&
test_cmp expect two.t
'
}
test_rebase_continue_update_encode ISO-8859-1 UTF-8 ISO8859-1.txt
test_rebase_continue_update_encode eucJP UTF-8 eucJP.txt
test_rebase_continue_update_encode eucJP ISO-2022-JP eucJP.txt
test_done