Git fork

t3437: test script for fixup [-C|-c] options in interactive rebase

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>

authored by

Charvi Mendiratta and committed by
Junio C Hamano
1d410cd8 9e3cebd9

+289
+4
t/lib-rebase.sh
··· 4 4 # 5 5 # - override the commit message with $FAKE_COMMIT_MESSAGE 6 6 # - amend the commit message with $FAKE_COMMIT_AMEND 7 + # - copy the original commit message to a file with $FAKE_MESSAGE_COPY 7 8 # - check that non-commit messages have a certain line count with $EXPECT_COUNT 8 9 # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT 9 10 # - rewrite a rebase -i script as directed by $FAKE_LINES. ··· 33 34 exit 34 35 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" 35 36 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" 37 + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" 36 38 exit 37 39 ;; 38 40 esac ··· 51 53 action="$line";; 52 54 exec_*|x_*|break|b) 53 55 echo "$line" | sed 's/_/ /g' >> "$1";; 56 + merge_*|fixup_*) 57 + action=$(echo "$line" | sed 's/_/ /g');; 54 58 "#") 55 59 echo '# comment' >> "$1";; 56 60 ">")
+213
t/t3437-rebase-fixup-options.sh
··· 1 + #!/bin/sh 2 + # 3 + # Copyright (c) 2018 Phillip Wood 4 + # 5 + 6 + test_description='git rebase interactive fixup options 7 + 8 + This test checks the "fixup [-C|-c]" command of rebase interactive. 9 + In addition to amending the contents of the commit, "fixup -C" 10 + replaces the original commit message with the message of the fixup 11 + commit. "fixup -c" also replaces the original message, but opens the 12 + editor to allow the user to edit the message before committing. 13 + ' 14 + 15 + . ./test-lib.sh 16 + 17 + . "$TEST_DIRECTORY"/lib-rebase.sh 18 + 19 + EMPTY="" 20 + 21 + test_commit_message () { 22 + rev="$1" && # commit or tag we want to test 23 + file="$2" && # test against the content of a file 24 + git show --no-patch --pretty=format:%B "$rev" >actual-message && 25 + if test "$2" = -m 26 + then 27 + str="$3" && # test against a string 28 + printf "%s\n" "$str" >tmp-expected-message && 29 + file="tmp-expected-message" 30 + fi 31 + test_cmp "$file" actual-message 32 + } 33 + 34 + get_author () { 35 + rev="$1" && 36 + git log -1 --pretty=format:"%an %ae" "$rev" 37 + } 38 + 39 + test_expect_success 'setup' ' 40 + cat >message <<-EOF && 41 + amend! B 42 + ${EMPTY} 43 + new subject 44 + ${EMPTY} 45 + new 46 + body 47 + EOF 48 + 49 + sed "1,2d" message >expected-message && 50 + 51 + test_commit A A && 52 + test_commit B B && 53 + get_author HEAD >expected-author && 54 + ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" && 55 + ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" && 56 + GIT_AUTHOR_NAME="Amend Author" && 57 + GIT_AUTHOR_EMAIL="amend@example.com" && 58 + test_commit "$(cat message)" A A1 A1 && 59 + test_commit A2 A && 60 + test_commit A3 A && 61 + GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" && 62 + GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" && 63 + git checkout -b conflicts-branch A && 64 + test_commit conflicts A && 65 + 66 + set_fake_editor && 67 + git checkout -b branch B && 68 + echo B1 >B && 69 + test_tick && 70 + git commit --fixup=HEAD -a && 71 + test_tick && 72 + git commit --allow-empty -F - <<-EOF && 73 + amend! B 74 + ${EMPTY} 75 + B 76 + ${EMPTY} 77 + edited 1 78 + EOF 79 + test_tick && 80 + git commit --allow-empty -F - <<-EOF && 81 + amend! amend! B 82 + ${EMPTY} 83 + B 84 + ${EMPTY} 85 + edited 1 86 + ${EMPTY} 87 + edited 2 88 + EOF 89 + echo B2 >B && 90 + test_tick && 91 + FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a && 92 + echo B3 >B && 93 + test_tick && 94 + git commit -a -F - <<-EOF && 95 + amend! amend! amend! B 96 + ${EMPTY} 97 + B 98 + ${EMPTY} 99 + edited 1 100 + ${EMPTY} 101 + edited 2 102 + ${EMPTY} 103 + edited 3 104 + EOF 105 + 106 + GIT_AUTHOR_NAME="Rebase Author" && 107 + GIT_AUTHOR_EMAIL="rebase.author@example.com" && 108 + GIT_COMMITTER_NAME="Rebase Committer" && 109 + GIT_COMMITTER_EMAIL="rebase.committer@example.com" 110 + ' 111 + 112 + test_expect_success 'simple fixup -C works' ' 113 + test_when_finished "test_might_fail git rebase --abort" && 114 + git checkout --detach A2 && 115 + FAKE_LINES="1 fixup_-C 2" git rebase -i B && 116 + test_cmp_rev HEAD^ B && 117 + test_cmp_rev HEAD^{tree} A2^{tree} && 118 + test_commit_message HEAD -m "A2" 119 + ' 120 + 121 + test_expect_success 'simple fixup -c works' ' 122 + test_when_finished "test_might_fail git rebase --abort" && 123 + git checkout --detach A2 && 124 + git log -1 --pretty=format:%B >expected-fixup-message && 125 + test_write_lines "" "Modified A2" >>expected-fixup-message && 126 + FAKE_LINES="1 fixup_-c 2" \ 127 + FAKE_COMMIT_AMEND="Modified A2" \ 128 + git rebase -i B && 129 + test_cmp_rev HEAD^ B && 130 + test_cmp_rev HEAD^{tree} A2^{tree} && 131 + test_commit_message HEAD expected-fixup-message 132 + ' 133 + 134 + test_expect_success 'fixup -C removes amend! from message' ' 135 + test_when_finished "test_might_fail git rebase --abort" && 136 + git checkout --detach A1 && 137 + FAKE_LINES="1 fixup_-C 2" git rebase -i A && 138 + test_cmp_rev HEAD^ A && 139 + test_cmp_rev HEAD^{tree} A1^{tree} && 140 + test_commit_message HEAD expected-message && 141 + get_author HEAD >actual-author && 142 + test_cmp expected-author actual-author 143 + ' 144 + 145 + test_expect_success 'fixup -C with conflicts gives correct message' ' 146 + test_when_finished "test_might_fail git rebase --abort" && 147 + git checkout --detach A1 && 148 + test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts && 149 + git checkout --theirs -- A && 150 + git add A && 151 + FAKE_COMMIT_AMEND=edited git rebase --continue && 152 + test_cmp_rev HEAD^ conflicts && 153 + test_cmp_rev HEAD^{tree} A1^{tree} && 154 + test_write_lines "" edited >>expected-message && 155 + test_commit_message HEAD expected-message && 156 + get_author HEAD >actual-author && 157 + test_cmp expected-author actual-author 158 + ' 159 + 160 + test_expect_success 'skipping fixup -C after fixup gives correct message' ' 161 + test_when_finished "test_might_fail git rebase --abort" && 162 + git checkout --detach A3 && 163 + test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A && 164 + git reset --hard && 165 + FAKE_COMMIT_AMEND=edited git rebase --continue && 166 + test_commit_message HEAD -m "B" 167 + ' 168 + 169 + test_expect_success 'sequence of fixup, fixup -C & squash --signoff works' ' 170 + git checkout --detach branch && 171 + FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \ 172 + FAKE_COMMIT_AMEND=squashed \ 173 + FAKE_MESSAGE_COPY=actual-squash-message \ 174 + git -c commit.status=false rebase -ik --signoff A && 175 + git diff-tree --exit-code --patch HEAD branch -- && 176 + test_cmp_rev HEAD^ A && 177 + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \ 178 + actual-squash-message 179 + ' 180 + 181 + test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' ' 182 + test_when_finished "test_might_fail git rebase --abort" && 183 + git checkout branch && git checkout --detach branch~2 && 184 + git log -1 --pretty=format:%b >expected-message && 185 + FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A && 186 + test_cmp_rev HEAD^ A && 187 + test_commit_message HEAD expected-message 188 + ' 189 + 190 + test_expect_success 'multiple fixup -c opens editor once' ' 191 + test_when_finished "test_might_fail git rebase --abort" && 192 + git checkout --detach A3 && 193 + base=$(git rev-parse HEAD~4) && 194 + FAKE_COMMIT_MESSAGE="Modified-A3" \ 195 + FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \ 196 + EXPECT_HEADER_COUNT=4 \ 197 + git rebase -i $base && 198 + test_cmp_rev $base HEAD^ && 199 + test 1 = $(git show | grep Modified-A3 | wc -l) 200 + ' 201 + 202 + test_expect_success 'sequence squash, fixup & fixup -c gives combined message' ' 203 + test_when_finished "test_might_fail git rebase --abort" && 204 + git checkout --detach A3 && 205 + FAKE_LINES="1 squash 2 fixup 3 fixup_-c 4" \ 206 + FAKE_MESSAGE_COPY=actual-combined-message \ 207 + git -c commit.status=false rebase -i A && 208 + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-combined-message" \ 209 + actual-combined-message && 210 + test_cmp_rev HEAD^ A 211 + ' 212 + 213 + test_done
+21
t/t3437/expected-combined-message
··· 1 + # This is a combination of 4 commits. 2 + # This is the 1st commit message: 3 + 4 + B 5 + 6 + # This is the commit message #2: 7 + 8 + # amend! B 9 + 10 + new subject 11 + 12 + new 13 + body 14 + 15 + # The commit message #3 will be skipped: 16 + 17 + # A2 18 + 19 + # This is the commit message #4: 20 + 21 + A3
+51
t/t3437/expected-squash-message
··· 1 + # This is a combination of 6 commits. 2 + # The 1st commit message will be skipped: 3 + 4 + # B 5 + # 6 + # Signed-off-by: Rebase Committer <rebase.committer@example.com> 7 + 8 + # The commit message #2 will be skipped: 9 + 10 + # fixup! B 11 + 12 + # The commit message #3 will be skipped: 13 + 14 + # amend! B 15 + # 16 + # B 17 + # 18 + # edited 1 19 + # 20 + # Signed-off-by: Rebase Committer <rebase.committer@example.com> 21 + 22 + # This is the commit message #4: 23 + 24 + # amend! amend! B 25 + 26 + B 27 + 28 + edited 1 29 + 30 + edited 2 31 + 32 + Signed-off-by: Rebase Committer <rebase.committer@example.com> 33 + 34 + # This is the commit message #5: 35 + 36 + # squash! amend! amend! B 37 + 38 + edited squash 39 + 40 + # This is the commit message #6: 41 + 42 + # amend! amend! amend! B 43 + 44 + B 45 + 46 + edited 1 47 + 48 + edited 2 49 + 50 + edited 3 51 + squashed