summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-03-26 14:59:03 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-03-26 14:59:03 -0700
commit89519f662c9e2b1c406fa72ba7923fcf5c028e89 (patch)
tree377d0feee3a6b52752c135c8d8457c898539768b /t
parentMerge branch 'cm/rebase-i-updates' (diff)
parentdoc/git-commit: add documentation for fixup=[amend|reword] options (diff)
downloadtgif-89519f662c9e2b1c406fa72ba7923fcf5c028e89.tar.xz
Merge branch 'cm/rebase-i-fixup-amend-reword'
"git commit --fixup=<commit>", which was to tweak the changes made to the contents while keeping the original log message intact, learned "--fixup=(amend|reword):<commit>", that can be used to tweak both the message and the contents, and only the message, respectively. * cm/rebase-i-fixup-amend-reword: doc/git-commit: add documentation for fixup=[amend|reword] options t3437: use --fixup with options to create amend! commit t7500: add tests for --fixup=[amend|reword] options commit: add a reword suboption to --fixup commit: add amend suboption to --fixup to create amend! commit sequencer: export and rename subject_length()
Diffstat (limited to 't')
-rwxr-xr-xt/t3437-rebase-fixup-options.sh30
-rwxr-xr-xt/t7500-commit-template-squash-signoff.sh159
2 files changed, 162 insertions, 27 deletions
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index a5a20354e3..d0bdc7ed02 100755
--- a/t/t3437-rebase-fixup-options.sh
+++ b/t/t3437-rebase-fixup-options.sh
@@ -72,40 +72,16 @@ test_expect_success 'setup' '
git commit --fixup=HEAD -a &&
git tag B1 &&
test_tick &&
- git commit --allow-empty -F - <<-EOF &&
- amend! B
- $EMPTY
- B
- $EMPTY
- edited 1
- EOF
+ FAKE_COMMIT_AMEND="edited 1" git commit --fixup=reword:B &&
test_tick &&
- git commit --allow-empty -F - <<-EOF &&
- amend! amend! B
- $EMPTY
- B
- $EMPTY
- edited 1
- $EMPTY
- edited 2
- EOF
+ FAKE_COMMIT_AMEND="edited 2" git commit --fixup=reword:HEAD &&
echo B2 >B &&
test_tick &&
FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
git tag B2 &&
echo B3 >B &&
test_tick &&
- git commit -a -F - <<-EOF &&
- amend! amend! amend! B
- $EMPTY
- B
- $EMPTY
- edited 1
- $EMPTY
- edited 2
- $EMPTY
- edited 3
- EOF
+ FAKE_COMMIT_AMEND="edited 3" git commit -a --fixup=amend:HEAD^ &&
git tag B3 &&
GIT_AUTHOR_NAME="Rebase Author" &&
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index e41ac18e7e..9092db5fdc 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -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 &&