t7500: add tests for --fixup=[amend|reword] options
Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Charvi Mendiratta <charvi077@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3270ae82ac
commit
3d1bda6b5b
@ -9,6 +9,8 @@ Tests for template, signoff, squash and -F functions.'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
. "$TEST_DIRECTORY"/lib-rebase.sh
|
||||
|
||||
commit_msg_is () {
|
||||
expect=commit_msg_is.expect
|
||||
actual=commit_msg_is.actual
|
||||
@ -279,6 +281,163 @@ test_expect_success 'commit --fixup -m"something" -m"extra"' '
|
||||
|
||||
extra"
|
||||
'
|
||||
get_commit_msg () {
|
||||
rev="$1" &&
|
||||
git log -1 --pretty=format:"%B" "$rev"
|
||||
}
|
||||
|
||||
test_expect_success 'commit --fixup=amend: creates amend! commit' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
cat >expected <<-EOF &&
|
||||
amend! $(git log -1 --format=%s HEAD~)
|
||||
|
||||
$(get_commit_msg HEAD~)
|
||||
|
||||
edited
|
||||
EOF
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_COMMIT_AMEND="edited" \
|
||||
git commit --fixup=amend:HEAD~
|
||||
) &&
|
||||
get_commit_msg HEAD >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success '--fixup=amend: --only ignores staged changes' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
cat >expected <<-EOF &&
|
||||
amend! $(git log -1 --format=%s HEAD~)
|
||||
|
||||
$(get_commit_msg HEAD~)
|
||||
|
||||
edited
|
||||
EOF
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_COMMIT_AMEND="edited" \
|
||||
git commit --fixup=amend:HEAD~ --only
|
||||
) &&
|
||||
get_commit_msg HEAD >actual &&
|
||||
test_cmp expected actual &&
|
||||
test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} &&
|
||||
test_cmp_rev HEAD@{1} HEAD^ &&
|
||||
test_expect_code 1 git diff --cached --exit-code &&
|
||||
git cat-file blob :foo >actual &&
|
||||
test_cmp foo actual
|
||||
'
|
||||
|
||||
test_expect_success '--fixup=reword: ignores staged changes' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
cat >expected <<-EOF &&
|
||||
amend! $(git log -1 --format=%s HEAD~)
|
||||
|
||||
$(get_commit_msg HEAD~)
|
||||
|
||||
edited
|
||||
EOF
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_COMMIT_AMEND="edited" \
|
||||
git commit --fixup=reword:HEAD~
|
||||
) &&
|
||||
get_commit_msg HEAD >actual &&
|
||||
test_cmp expected actual &&
|
||||
test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} &&
|
||||
test_cmp_rev HEAD@{1} HEAD^ &&
|
||||
test_expect_code 1 git diff --cached --exit-code &&
|
||||
git cat-file blob :foo >actual &&
|
||||
test_cmp foo actual
|
||||
'
|
||||
|
||||
test_expect_success '--fixup=reword: error out with -m option' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
echo "fatal: cannot combine -m with --fixup:reword" >expect &&
|
||||
test_must_fail git commit --fixup=reword:HEAD~ -m "reword commit message" 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '--fixup=amend: error out with -m option' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
echo "fatal: cannot combine -m with --fixup:amend" >expect &&
|
||||
test_must_fail git commit --fixup=amend:HEAD~ -m "amend commit message" 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'consecutive amend! commits remove amend! line from commit msg body' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
cat >expected <<-EOF &&
|
||||
amend! amend! $(git log -1 --format=%s HEAD~)
|
||||
|
||||
$(get_commit_msg HEAD~)
|
||||
|
||||
edited 1
|
||||
|
||||
edited 2
|
||||
EOF
|
||||
echo "reword new commit message" >actual &&
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_COMMIT_AMEND="edited 1" \
|
||||
git commit --fixup=reword:HEAD~ &&
|
||||
FAKE_COMMIT_AMEND="edited 2" \
|
||||
git commit --fixup=reword:HEAD
|
||||
) &&
|
||||
get_commit_msg HEAD >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'deny to create amend! commit if its commit msg body is empty' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
echo "Aborting commit due to empty commit message body." >expected &&
|
||||
(
|
||||
set_fake_editor &&
|
||||
test_must_fail env FAKE_COMMIT_MESSAGE="amend! target message subject line" \
|
||||
git commit --fixup=amend:HEAD~ 2>actual
|
||||
) &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'amend! commit allows empty commit msg body with --allow-empty-message' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
cat >expected <<-EOF &&
|
||||
amend! $(git log -1 --format=%s HEAD~)
|
||||
EOF
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_COMMIT_MESSAGE="amend! target message subject line" \
|
||||
git commit --fixup=amend:HEAD~ --allow-empty-message &&
|
||||
get_commit_msg HEAD >actual
|
||||
) &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_fixup_reword_opt () {
|
||||
test_expect_success C_LOCALE_OUTPUT "--fixup=reword: incompatible with $1" "
|
||||
echo 'fatal: reword option of --fixup is mutually exclusive with'\
|
||||
'--patch/--interactive/--all/--include/--only' >expect &&
|
||||
test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual &&
|
||||
test_cmp expect actual
|
||||
"
|
||||
}
|
||||
|
||||
for opt in --all --include --only --interactive --patch
|
||||
do
|
||||
test_fixup_reword_opt $opt
|
||||
done
|
||||
|
||||
test_expect_success '--fixup=reword: give error with pathsec' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
echo "fatal: cannot combine reword option of --fixup with path '\''foo'\''" >expect &&
|
||||
test_must_fail git commit --fixup=reword:HEAD~ -- foo 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '--fixup=reword: -F give error message' '
|
||||
echo "fatal: Only one of -c/-C/-F/--fixup can be used." >expect &&
|
||||
test_must_fail git commit --fixup=reword:HEAD~ -F msg 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'commit --squash works with -F' '
|
||||
commit_for_rebase_autosquash_setup &&
|
||||
|
Loading…
Reference in New Issue
Block a user