| 1 | #!/bin/sh |
| 2 | # |
| 3 | |
| 4 | test_description='git rebase --trailer integration tests |
| 5 | We verify that --trailer works with the merge backend, |
| 6 | and that it is rejected early when the apply backend is requested.' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | . "$TEST_DIRECTORY"/lib-rebase.sh # test_commit_message, helpers |
| 13 | |
| 14 | REVIEWED_BY_TRAILER="Reviewed-by: Dev <dev@example.com>" |
| 15 | SP=" " |
| 16 | |
| 17 | test_expect_success 'setup repo with a small history' ' |
| 18 | git commit --allow-empty -m "Initial empty commit" && |
| 19 | test_commit first file a && |
| 20 | test_commit second file && |
| 21 | git checkout -b conflict-branch first && |
| 22 | test_commit file-2 file-2 && |
| 23 | test_commit conflict file && |
| 24 | test_commit third file && |
| 25 | git checkout main |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'apply backend is rejected with --trailer' ' |
| 29 | git checkout -B apply-backend third && |
| 30 | test_expect_code 128 \ |
| 31 | git rebase --apply --trailer "$REVIEWED_BY_TRAILER" HEAD^ 2>err && |
| 32 | test_grep "fatal: --trailer requires the merge backend" err |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'reject empty --trailer argument' ' |
| 36 | git checkout -B empty-trailer third && |
| 37 | test_expect_code 128 git rebase --trailer "" HEAD^ 2>err && |
| 38 | test_grep "empty --trailer" err |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'reject trailer with missing key before separator' ' |
| 42 | git checkout -B missing-key third && |
| 43 | test_expect_code 128 git rebase --trailer ": no-key" HEAD^ 2>err && |
| 44 | test_grep "missing key before separator" err |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'allow trailer with missing value after separator' ' |
| 48 | git checkout -B missing-value third && |
| 49 | git rebase --trailer "Acked-by:" HEAD^ && |
| 50 | test_commit_message HEAD <<-EOF |
| 51 | third |
| 52 | |
| 53 | Acked-by:${SP} |
| 54 | EOF |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' ' |
| 58 | git checkout -B replace-policy third && |
| 59 | git -c trailer.Bug.ifexists=replace -c trailer.Bug.ifmissing=add \ |
| 60 | rebase --trailer "Bug: 123" --trailer "Bug: 456" HEAD^ && |
| 61 | test_commit_message HEAD <<-EOF |
| 62 | third |
| 63 | |
| 64 | Bug: 456 |
| 65 | EOF |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'multiple Signed-off-by trailers all preserved' ' |
| 69 | git checkout -B multiple-signoff third && |
| 70 | git rebase --trailer "Signed-off-by: Dev A <a@example.com>" \ |
| 71 | --trailer "Signed-off-by: Dev B <b@example.com>" HEAD^ && |
| 72 | test_commit_message HEAD <<-EOF |
| 73 | third |
| 74 | |
| 75 | Signed-off-by: Dev A <a@example.com> |
| 76 | Signed-off-by: Dev B <b@example.com> |
| 77 | EOF |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'rebase --trailer adds trailer after conflicts' ' |
| 81 | git checkout -B trailer-conflict third && |
| 82 | test_commit fourth file && |
| 83 | test_must_fail git rebase --trailer "$REVIEWED_BY_TRAILER" second && |
| 84 | git checkout --theirs file && |
| 85 | git add file && |
| 86 | git rebase --continue && |
| 87 | test_commit_message HEAD <<-EOF && |
| 88 | fourth |
| 89 | |
| 90 | $REVIEWED_BY_TRAILER |
| 91 | EOF |
| 92 | test_commit_message HEAD^ <<-EOF |
| 93 | third |
| 94 | |
| 95 | $REVIEWED_BY_TRAILER |
| 96 | EOF |
| 97 | ' |
| 98 | |
| 99 | test_expect_success '--trailer handles fixup commands in todo list' ' |
| 100 | git checkout -B fixup-trailer third && |
| 101 | test_commit fixup-base base && |
| 102 | test_commit fixup-second second && |
| 103 | cat >todo <<-\EOF && |
| 104 | pick fixup-base fixup-base |
| 105 | fixup fixup-second fixup-second |
| 106 | EOF |
| 107 | ( |
| 108 | set_replace_editor todo && |
| 109 | git rebase -i --trailer "$REVIEWED_BY_TRAILER" HEAD~2 |
| 110 | ) && |
| 111 | test_commit_message HEAD <<-EOF && |
| 112 | fixup-base |
| 113 | |
| 114 | $REVIEWED_BY_TRAILER |
| 115 | EOF |
| 116 | git reset --hard fixup-second && |
| 117 | cat >todo <<-\EOF && |
| 118 | pick fixup-base fixup-base |
| 119 | fixup -C fixup-second fixup-second |
| 120 | EOF |
| 121 | ( |
| 122 | set_replace_editor todo && |
| 123 | git rebase -i --trailer "$REVIEWED_BY_TRAILER" HEAD~2 |
| 124 | ) && |
| 125 | test_commit_message HEAD <<-EOF |
| 126 | fixup-second |
| 127 | |
| 128 | $REVIEWED_BY_TRAILER |
| 129 | EOF |
| 130 | ' |
| 131 | |
| 132 | test_expect_success 'rebase --root honors trailer.<name>.key' ' |
| 133 | git checkout -B root-trailer first && |
| 134 | git -c trailer.review.key=Reviewed-by rebase --root \ |
| 135 | --trailer=review="Dev <dev@example.com>" && |
| 136 | test_commit_message HEAD <<-EOF && |
| 137 | first |
| 138 | |
| 139 | Reviewed-by: Dev <dev@example.com> |
| 140 | EOF |
| 141 | test_commit_message HEAD^ <<-EOF |
| 142 | Initial empty commit |
| 143 | |
| 144 | Reviewed-by: Dev <dev@example.com> |
| 145 | EOF |
| 146 | ' |
| 147 | test_done |