| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='rebase should handle arbitrary git message' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 10 | |
| 11 | cat >F <<\EOF |
| 12 | This is an example of a commit log message |
| 13 | that does not conform to git commit convention. |
| 14 | |
| 15 | It has two paragraphs, but its first paragraph is not friendly |
| 16 | to oneline summary format. |
| 17 | EOF |
| 18 | |
| 19 | cat >G <<\EOF |
| 20 | commit log message containing a diff |
| 21 | EOF |
| 22 | |
| 23 | |
| 24 | test_expect_success setup ' |
| 25 | |
| 26 | >file1 && |
| 27 | >file2 && |
| 28 | git add file1 file2 && |
| 29 | test_tick && |
| 30 | git commit -m "Initial commit" && |
| 31 | git branch diff-in-message && |
| 32 | git branch empty-message-merge && |
| 33 | |
| 34 | git checkout -b multi-line-subject && |
| 35 | cat F >file2 && |
| 36 | git add file2 && |
| 37 | test_tick && |
| 38 | git commit -F F && |
| 39 | |
| 40 | git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 && |
| 41 | |
| 42 | git checkout diff-in-message && |
| 43 | echo "commit log message containing a diff" >G && |
| 44 | echo "" >>G && |
| 45 | cat G >file2 && |
| 46 | git add file2 && |
| 47 | git diff --cached >>G && |
| 48 | test_tick && |
| 49 | git commit -F G && |
| 50 | |
| 51 | git cat-file commit HEAD | sed -e "1,/^\$/d" >G0 && |
| 52 | |
| 53 | git checkout empty-message-merge && |
| 54 | echo file3 >file3 && |
| 55 | git add file3 && |
| 56 | git commit --allow-empty-message -m "" && |
| 57 | |
| 58 | git checkout main && |
| 59 | |
| 60 | echo One >file1 && |
| 61 | test_tick && |
| 62 | git add file1 && |
| 63 | git commit -m "Second commit" |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'rebase commit with multi-line subject' ' |
| 67 | |
| 68 | git rebase main multi-line-subject && |
| 69 | git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 && |
| 70 | |
| 71 | test_cmp F0 F1 && |
| 72 | test_cmp F F0 |
| 73 | ' |
| 74 | |
| 75 | test_expect_success 'rebase commit with diff in message' ' |
| 76 | git rebase main diff-in-message && |
| 77 | git cat-file commit HEAD | sed -e "1,/^$/d" >G1 && |
| 78 | test_cmp G0 G1 && |
| 79 | test_cmp G G0 |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'rebase -m commit with empty message' ' |
| 83 | git rebase -m main empty-message-merge |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'rebase -i commit with empty message' ' |
| 87 | git checkout diff-in-message && |
| 88 | set_fake_editor && |
| 89 | test_must_fail env FAKE_COMMIT_MESSAGE=" " FAKE_LINES="reword 1" \ |
| 90 | git rebase -i HEAD^ |
| 91 | ' |
| 92 | |
| 93 | test_done |