Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git commit porcelain-ish' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 7 | commit_msg_is () { |
| 8 | expect=commit_msg_is.expect |
| 9 | actual=commit_msg_is.actual |
| 10 | |
| 11 | printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual && |
| 12 | printf "%s" "$1" >$expect && |
| 13 | test_i18ncmp $expect $actual |
| 14 | } |
| 15 | |
Tay Ray Chuan | cee9f2b | 2010-05-27 23:34:51 +0800 | [diff] [blame] | 16 | # Arguments: [<prefix] [<commit message>] [<commit options>] |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 17 | check_summary_oneline() { |
| 18 | test_tick && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 19 | git commit ${3+"$3"} -m "$2" >raw && |
| 20 | head -n 1 raw >act && |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 21 | |
| 22 | # branch name |
| 23 | SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && |
| 24 | |
| 25 | # append the "special" prefix, like "root-commit", "detached HEAD" |
| 26 | if test -n "$1" |
| 27 | then |
| 28 | SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)" |
| 29 | fi |
| 30 | |
| 31 | # abbrev SHA-1 |
| 32 | SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')" |
| 33 | echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp && |
| 34 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 35 | test_i18ncmp exp act |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | test_expect_success 'output summary format' ' |
| 39 | |
| 40 | echo new >file1 && |
| 41 | git add file1 && |
| 42 | check_summary_oneline "root-commit" "initial" && |
| 43 | |
| 44 | echo change >>file1 && |
Ævar Arnfjörð Bjarmason | 7f5673d | 2011-02-22 23:41:47 +0000 | [diff] [blame] | 45 | git add file1 |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'output summary format: root-commit' ' |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 49 | check_summary_oneline "" "a change" |
| 50 | ' |
| 51 | |
Tay Ray Chuan | a45e1a8 | 2010-06-12 22:15:39 +0800 | [diff] [blame] | 52 | test_expect_success 'output summary format for commit with an empty diff' ' |
Tay Ray Chuan | cee9f2b | 2010-05-27 23:34:51 +0800 | [diff] [blame] | 53 | |
| 54 | check_summary_oneline "" "empty" "--allow-empty" |
| 55 | ' |
| 56 | |
Tay Ray Chuan | a45e1a8 | 2010-06-12 22:15:39 +0800 | [diff] [blame] | 57 | test_expect_success 'output summary format for merges' ' |
Tay Ray Chuan | cee9f2b | 2010-05-27 23:34:51 +0800 | [diff] [blame] | 58 | |
| 59 | git checkout -b recursive-base && |
| 60 | test_commit base file1 && |
| 61 | |
| 62 | git checkout -b recursive-a recursive-base && |
| 63 | test_commit commit-a file1 && |
| 64 | |
| 65 | git checkout -b recursive-b recursive-base && |
| 66 | test_commit commit-b file1 && |
| 67 | |
| 68 | # conflict |
| 69 | git checkout recursive-a && |
| 70 | test_must_fail git merge recursive-b && |
| 71 | # resolve the conflict |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 72 | echo commit-a >file1 && |
Tay Ray Chuan | cee9f2b | 2010-05-27 23:34:51 +0800 | [diff] [blame] | 73 | git add file1 && |
| 74 | check_summary_oneline "" "Merge" |
| 75 | ' |
| 76 | |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 77 | output_tests_cleanup() { |
| 78 | # this is needed for "do not fire editor in the presence of conflicts" |
| 79 | git checkout master && |
| 80 | |
| 81 | # this is needed for the "partial removal" test to pass |
| 82 | git rm file1 && |
| 83 | git commit -m "cleanup" |
| 84 | } |
| 85 | |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 86 | test_expect_success 'the basics' ' |
| 87 | |
Tay Ray Chuan | fc6fa0d | 2010-05-27 23:34:50 +0800 | [diff] [blame] | 88 | output_tests_cleanup && |
| 89 | |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 90 | echo doing partial >"commit is" && |
| 91 | mkdir not && |
| 92 | echo very much encouraged but we should >not/forbid && |
| 93 | git add "commit is" not && |
| 94 | echo update added "commit is" file >"commit is" && |
| 95 | echo also update another >not/forbid && |
| 96 | test_tick && |
| 97 | git commit -a -m "initial with -a" && |
| 98 | |
| 99 | git cat-file blob HEAD:"commit is" >current.1 && |
| 100 | git cat-file blob HEAD:not/forbid >current.2 && |
| 101 | |
| 102 | cmp current.1 "commit is" && |
| 103 | cmp current.2 not/forbid |
| 104 | |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'partial' ' |
| 108 | |
| 109 | echo another >"commit is" && |
| 110 | echo another >not/forbid && |
| 111 | test_tick && |
| 112 | git commit -m "partial commit to handle a file" "commit is" && |
| 113 | |
| 114 | changed=$(git diff-tree --name-only HEAD^ HEAD) && |
| 115 | test "$changed" = "commit is" |
| 116 | |
| 117 | ' |
| 118 | |
Tay Ray Chuan | e8f3016 | 2010-05-24 16:51:17 +0800 | [diff] [blame] | 119 | test_expect_success 'partial modification in a subdirectory' ' |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 120 | |
| 121 | test_tick && |
| 122 | git commit -m "partial commit to subdirectory" not && |
| 123 | |
| 124 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && |
| 125 | test "$changed" = "not/forbid" |
| 126 | |
| 127 | ' |
| 128 | |
| 129 | test_expect_success 'partial removal' ' |
| 130 | |
| 131 | git rm not/forbid && |
| 132 | git commit -m "partial commit to remove not/forbid" not && |
| 133 | |
| 134 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && |
| 135 | test "$changed" = "not/forbid" && |
| 136 | remain=$(git ls-tree -r --name-only HEAD) && |
| 137 | test "$remain" = "commit is" |
| 138 | |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'sign off' ' |
| 142 | |
| 143 | >positive && |
| 144 | git add positive && |
| 145 | git commit -s -m "thank you" && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 146 | git cat-file commit HEAD >commit.msg && |
| 147 | sed -ne "s/Signed-off-by: //p" commit.msg >actual && |
| 148 | git var GIT_COMMITTER_IDENT >ident && |
| 149 | sed -e "s/>.*/>/" ident >expected && |
| 150 | test_cmp expected actual |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 151 | |
| 152 | ' |
| 153 | |
| 154 | test_expect_success 'multiple -m' ' |
| 155 | |
| 156 | >negative && |
| 157 | git add negative && |
| 158 | git commit -m "one" -m "two" -m "three" && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 159 | actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) && |
| 160 | expected=$(test_write_lines "one" "" "two" "" "three") && |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 161 | test "z$actual" = "z$expected" |
| 162 | |
| 163 | ' |
| 164 | |
| 165 | test_expect_success 'verbose' ' |
| 166 | |
| 167 | echo minus >negative && |
| 168 | git add negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 169 | git status -v >raw && |
| 170 | sed -ne "/^diff --git /p" raw >actual && |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 171 | echo "diff --git a/negative b/negative" >expect && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 172 | test_cmp expect actual |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 173 | |
| 174 | ' |
| 175 | |
Jeff King | 4f672ad | 2008-10-26 00:49:35 -0400 | [diff] [blame] | 176 | test_expect_success 'verbose respects diff config' ' |
| 177 | |
Jeff King | 0fcf760 | 2017-10-03 09:43:47 -0400 | [diff] [blame] | 178 | test_config diff.noprefix true && |
Jeff King | 4f672ad | 2008-10-26 00:49:35 -0400 | [diff] [blame] | 179 | git status -v >actual && |
Jeff King | 0fcf760 | 2017-10-03 09:43:47 -0400 | [diff] [blame] | 180 | grep "diff --git negative negative" actual |
Jeff King | 4f672ad | 2008-10-26 00:49:35 -0400 | [diff] [blame] | 181 | ' |
| 182 | |
Brandon Casey | 5b012c8 | 2013-02-18 20:17:05 -0800 | [diff] [blame] | 183 | mesg_with_comment_and_newlines=' |
| 184 | # text |
| 185 | |
| 186 | ' |
| 187 | |
| 188 | test_expect_success 'prepare file with comment line and trailing newlines' ' |
| 189 | printf "%s" "$mesg_with_comment_and_newlines" >expect |
| 190 | ' |
| 191 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 192 | test_expect_success 'cleanup commit messages (verbatim option,-t)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 193 | |
| 194 | echo >>negative && |
Brandon Casey | 67dabab | 2013-02-18 20:17:04 -0800 | [diff] [blame] | 195 | git commit --cleanup=verbatim --no-status -t expect -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 196 | git cat-file -p HEAD >raw && |
| 197 | sed -e "1,/^\$/d" raw >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 198 | test_cmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 199 | |
| 200 | ' |
| 201 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 202 | test_expect_success 'cleanup commit messages (verbatim option,-F)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 203 | |
| 204 | echo >>negative && |
| 205 | git commit --cleanup=verbatim -F expect -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 206 | git cat-file -p HEAD >raw && |
| 207 | sed -e "1,/^\$/d" raw >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 208 | test_cmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 209 | |
| 210 | ' |
| 211 | |
Brandon Casey | a24a41e | 2013-02-18 20:17:06 -0800 | [diff] [blame] | 212 | test_expect_success 'cleanup commit messages (verbatim option,-m)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 213 | |
| 214 | echo >>negative && |
Brandon Casey | 5b012c8 | 2013-02-18 20:17:05 -0800 | [diff] [blame] | 215 | git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 216 | git cat-file -p HEAD >raw && |
| 217 | sed -e "1,/^\$/d" raw >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 218 | test_cmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 219 | |
| 220 | ' |
| 221 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 222 | test_expect_success 'cleanup commit messages (whitespace option,-F)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 223 | |
| 224 | echo >>negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 225 | test_write_lines "" "# text" "" >text && |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 226 | echo "# text" >expect && |
| 227 | git commit --cleanup=whitespace -F text -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 228 | git cat-file -p HEAD >raw && |
| 229 | sed -e "1,/^\$/d" raw >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 230 | test_cmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 231 | |
| 232 | ' |
| 233 | |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 234 | test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' |
| 235 | |
| 236 | echo >>negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 237 | cat >text <<-\EOF && |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 238 | |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 239 | # to be kept |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 240 | |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 241 | # ------------------------ >8 ------------------------ |
| 242 | # to be kept, too |
| 243 | # ------------------------ >8 ------------------------ |
| 244 | to be removed |
| 245 | # ------------------------ >8 ------------------------ |
| 246 | to be removed, too |
| 247 | EOF |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 248 | |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 249 | cat >expect <<-\EOF && |
| 250 | # to be kept |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 251 | |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 252 | # ------------------------ >8 ------------------------ |
| 253 | # to be kept, too |
| 254 | EOF |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 255 | git commit --cleanup=scissors -e -F text -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 256 | git cat-file -p HEAD >raw && |
| 257 | sed -e "1,/^\$/d" raw >actual && |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 258 | test_cmp expect actual |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 259 | ' |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 260 | |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 261 | test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' ' |
| 262 | |
| 263 | echo >>negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 264 | cat >text <<-\EOF && |
| 265 | # ------------------------ >8 ------------------------ |
| 266 | to be removed |
| 267 | EOF |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 268 | git commit --cleanup=scissors -e -F text -a --allow-empty-message && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 269 | git cat-file -p HEAD >raw && |
| 270 | sed -e "1,/^\$/d" raw >actual && |
SZEDER Gábor | fbfa097 | 2015-06-09 02:28:34 +0200 | [diff] [blame] | 271 | test_must_be_empty actual |
Nguyễn Thái Ngọc Duy | 75df1f4 | 2014-02-17 19:15:32 +0700 | [diff] [blame] | 272 | ' |
| 273 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 274 | test_expect_success 'cleanup commit messages (strip option,-F)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 275 | |
| 276 | echo >>negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 277 | test_write_lines "" "# text" "sample" "" >text && |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 278 | echo sample >expect && |
| 279 | git commit --cleanup=strip -F text -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 280 | git cat-file -p HEAD >raw && |
| 281 | sed -e "1,/^\$/d" raw >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 282 | test_cmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 283 | |
| 284 | ' |
| 285 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 286 | test_expect_success 'cleanup commit messages (strip option,-F,-e)' ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 287 | |
| 288 | echo >>negative && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 289 | test_write_lines "" "sample" "" >text && |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 290 | git commit -e -F text -a && |
Ævar Arnfjörð Bjarmason | 0b430a1 | 2011-02-22 23:41:48 +0000 | [diff] [blame] | 291 | head -n 4 .git/COMMIT_EDITMSG >actual |
| 292 | ' |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 293 | |
Ævar Arnfjörð Bjarmason | 0b430a1 | 2011-02-22 23:41:48 +0000 | [diff] [blame] | 294 | echo "sample |
| 295 | |
| 296 | # Please enter the commit message for your changes. Lines starting |
| 297 | # with '#' will be ignored, and an empty message aborts the commit." >expect |
| 298 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 299 | test_expect_success 'cleanup commit messages (strip option,-F,-e): output' ' |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 300 | test_i18ncmp expect actual |
Alex Riesen | 5f06573 | 2007-12-22 19:46:24 +0100 | [diff] [blame] | 301 | ' |
| 302 | |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 303 | test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' ' |
| 304 | test_must_fail git commit --cleanup=non-existent |
| 305 | ' |
| 306 | |
| 307 | test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' ' |
| 308 | test_must_fail git -c commit.cleanup=non-existent commit |
| 309 | ' |
| 310 | |
| 311 | test_expect_success 'cleanup commit message (no config and no option uses default)' ' |
| 312 | echo content >>file && |
| 313 | git add file && |
Brandon Casey | 24e099f | 2013-02-22 15:13:00 -0800 | [diff] [blame] | 314 | ( |
| 315 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && |
| 316 | git commit --no-status |
| 317 | ) && |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 318 | commit_msg_is "commit message" |
| 319 | ' |
| 320 | |
| 321 | test_expect_success 'cleanup commit message (option overrides default)' ' |
| 322 | echo content >>file && |
| 323 | git add file && |
Brandon Casey | 24e099f | 2013-02-22 15:13:00 -0800 | [diff] [blame] | 324 | ( |
| 325 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && |
| 326 | git commit --cleanup=whitespace --no-status |
| 327 | ) && |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 328 | commit_msg_is "commit message # comment" |
| 329 | ' |
| 330 | |
| 331 | test_expect_success 'cleanup commit message (config overrides default)' ' |
| 332 | echo content >>file && |
| 333 | git add file && |
Brandon Casey | 24e099f | 2013-02-22 15:13:00 -0800 | [diff] [blame] | 334 | ( |
| 335 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && |
| 336 | git -c commit.cleanup=whitespace commit --no-status |
| 337 | ) && |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 338 | commit_msg_is "commit message # comment" |
| 339 | ' |
| 340 | |
| 341 | test_expect_success 'cleanup commit message (option overrides config)' ' |
| 342 | echo content >>file && |
| 343 | git add file && |
Brandon Casey | 24e099f | 2013-02-22 15:13:00 -0800 | [diff] [blame] | 344 | ( |
| 345 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && |
| 346 | git -c commit.cleanup=whitespace commit --cleanup=default |
| 347 | ) && |
Ralf Thielow | 51fb3a3 | 2013-01-10 18:45:59 +0100 | [diff] [blame] | 348 | commit_msg_is "commit message" |
| 349 | ' |
| 350 | |
| 351 | test_expect_success 'cleanup commit message (default, -m)' ' |
| 352 | echo content >>file && |
| 353 | git add file && |
| 354 | git commit -m "message #comment " && |
| 355 | commit_msg_is "message #comment" |
| 356 | ' |
| 357 | |
| 358 | test_expect_success 'cleanup commit message (whitespace option, -m)' ' |
| 359 | echo content >>file && |
| 360 | git add file && |
| 361 | git commit --cleanup=whitespace --no-status -m "message #comment " && |
| 362 | commit_msg_is "message #comment" |
| 363 | ' |
| 364 | |
| 365 | test_expect_success 'cleanup commit message (whitespace config, -m)' ' |
| 366 | echo content >>file && |
| 367 | git add file && |
| 368 | git -c commit.cleanup=whitespace commit --no-status -m "message #comment " && |
| 369 | commit_msg_is "message #comment" |
| 370 | ' |
| 371 | |
Jeff King | 1f4bf34 | 2012-07-26 16:30:29 -0400 | [diff] [blame] | 372 | test_expect_success 'message shows author when it is not equal to committer' ' |
Santi Béjar | e83dbe8 | 2008-05-04 18:04:50 +0200 | [diff] [blame] | 373 | echo >>negative && |
Jeff King | ceacd91 | 2012-07-26 16:31:15 -0400 | [diff] [blame] | 374 | git commit -e -m "sample" -a && |
Jeff King | 1f4bf34 | 2012-07-26 16:30:29 -0400 | [diff] [blame] | 375 | test_i18ngrep \ |
| 376 | "^# Author: *A U Thor <author@example.com>\$" \ |
| 377 | .git/COMMIT_EDITMSG |
Santi Béjar | e83dbe8 | 2008-05-04 18:04:50 +0200 | [diff] [blame] | 378 | ' |
| 379 | |
Jeff King | b7242b8 | 2014-05-01 21:10:01 -0400 | [diff] [blame] | 380 | test_expect_success 'message shows date when it is explicitly set' ' |
| 381 | git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" && |
| 382 | test_i18ngrep \ |
| 383 | "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \ |
| 384 | .git/COMMIT_EDITMSG |
| 385 | ' |
| 386 | |
Jeff King | 1d7dc26 | 2012-07-26 16:32:31 -0400 | [diff] [blame] | 387 | test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' |
Santi Béjar | bb1ae3f | 2008-05-04 18:04:51 +0200 | [diff] [blame] | 388 | |
| 389 | echo >>negative && |
Junio C Hamano | 7845944 | 2008-06-03 18:08:08 -0700 | [diff] [blame] | 390 | ( |
Elijah Newren | 00648ba | 2010-10-03 14:00:14 -0600 | [diff] [blame] | 391 | sane_unset GIT_COMMITTER_EMAIL && |
| 392 | sane_unset GIT_COMMITTER_NAME && |
Jeff King | 1d7dc26 | 2012-07-26 16:32:31 -0400 | [diff] [blame] | 393 | git commit -e -m "sample" -a |
Junio C Hamano | 7845944 | 2008-06-03 18:08:08 -0700 | [diff] [blame] | 394 | ) && |
Jeff King | 1f4bf34 | 2012-07-26 16:30:29 -0400 | [diff] [blame] | 395 | # the ident is calculated from the system, so we cannot |
| 396 | # check the actual value, only that it is there |
| 397 | test_i18ngrep "^# Committer: " .git/COMMIT_EDITMSG |
Santi Béjar | bb1ae3f | 2008-05-04 18:04:51 +0200 | [diff] [blame] | 398 | ' |
| 399 | |
Jeff King | a9ebc43 | 2012-07-26 16:27:55 -0400 | [diff] [blame] | 400 | write_script .git/FAKE_EDITOR <<EOF |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 401 | echo editor started >"$(pwd)/.git/result" |
Paolo Bonzini | ec84bd0 | 2008-02-05 11:01:46 +0100 | [diff] [blame] | 402 | exit 0 |
| 403 | EOF |
Paolo Bonzini | ec84bd0 | 2008-02-05 11:01:46 +0100 | [diff] [blame] | 404 | |
Ævar Arnfjörð Bjarmason | cf7a851 | 2019-06-20 22:42:27 +0200 | [diff] [blame] | 405 | test_expect_success !FAIL_PREREQS,!AUTOIDENT 'do not fire editor when committer is bogus' ' |
Ramsay Jones | f84df81 | 2015-04-28 13:04:44 +0100 | [diff] [blame] | 406 | >.git/result && |
Jeff King | 8c8b3bc | 2012-07-26 16:32:50 -0400 | [diff] [blame] | 407 | |
| 408 | echo >>negative && |
| 409 | ( |
| 410 | sane_unset GIT_COMMITTER_EMAIL && |
| 411 | sane_unset GIT_COMMITTER_NAME && |
| 412 | GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && |
| 413 | export GIT_EDITOR && |
| 414 | test_must_fail git commit -e -m sample -a |
| 415 | ) && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 416 | test_must_be_empty .git/result |
Jeff King | 8c8b3bc | 2012-07-26 16:32:50 -0400 | [diff] [blame] | 417 | ' |
| 418 | |
René Scharfe | 2520677 | 2013-05-25 23:43:34 +0200 | [diff] [blame] | 419 | test_expect_success 'do not fire editor if -m <msg> was given' ' |
| 420 | echo tick >file && |
| 421 | git add file && |
| 422 | echo "editor not started" >.git/result && |
| 423 | (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) && |
| 424 | test "$(cat .git/result)" = "editor not started" |
| 425 | ' |
| 426 | |
| 427 | test_expect_success 'do not fire editor if -m "" was given' ' |
| 428 | echo tock >file && |
| 429 | git add file && |
| 430 | echo "editor not started" >.git/result && |
| 431 | (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \ |
| 432 | git commit -m "" --allow-empty-message) && |
| 433 | test "$(cat .git/result)" = "editor not started" |
| 434 | ' |
| 435 | |
Paolo Bonzini | ec84bd0 | 2008-02-05 11:01:46 +0100 | [diff] [blame] | 436 | test_expect_success 'do not fire editor in the presence of conflicts' ' |
| 437 | |
Junio C Hamano | a3c91e0 | 2008-06-03 18:10:08 -0700 | [diff] [blame] | 438 | git clean -f && |
| 439 | echo f >g && |
| 440 | git add g && |
| 441 | git commit -m "add g" && |
| 442 | git branch second && |
| 443 | echo master >g && |
| 444 | echo g >h && |
| 445 | git add g h && |
| 446 | git commit -m "modify g and add h" && |
| 447 | git checkout second && |
| 448 | echo second >g && |
| 449 | git add g && |
| 450 | git commit -m second && |
| 451 | # Must fail due to conflict |
| 452 | test_must_fail git cherry-pick -n master && |
| 453 | echo "editor not started" >.git/result && |
Brandon Casey | e200783 | 2008-06-19 12:32:02 -0500 | [diff] [blame] | 454 | ( |
Jeff King | 34565f2 | 2012-07-26 16:28:00 -0400 | [diff] [blame] | 455 | GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && |
Brandon Casey | e200783 | 2008-06-19 12:32:02 -0500 | [diff] [blame] | 456 | export GIT_EDITOR && |
| 457 | test_must_fail git commit |
| 458 | ) && |
Junio C Hamano | a3c91e0 | 2008-06-03 18:10:08 -0700 | [diff] [blame] | 459 | test "$(cat .git/result)" = "editor not started" |
Paolo Bonzini | ec84bd0 | 2008-02-05 11:01:46 +0100 | [diff] [blame] | 460 | ' |
| 461 | |
Jeff King | a9ebc43 | 2012-07-26 16:27:55 -0400 | [diff] [blame] | 462 | write_script .git/FAKE_EDITOR <<EOF |
Paolo Bonzini | ad5fa3c | 2008-05-29 16:55:53 +0200 | [diff] [blame] | 463 | # kill -TERM command added below. |
| 464 | EOF |
| 465 | |
Johannes Sixt | fb9a2be | 2009-03-25 13:21:15 +0100 | [diff] [blame] | 466 | test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' |
Paolo Bonzini | ad5fa3c | 2008-05-29 16:55:53 +0200 | [diff] [blame] | 467 | echo >>negative && |
Brandon Casey | 09b78bc | 2008-07-22 16:21:10 -0500 | [diff] [blame] | 468 | ! "$SHELL_PATH" -c '\'' |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 469 | echo kill -TERM $$ >>.git/FAKE_EDITOR |
Brandon Casey | 09b78bc | 2008-07-22 16:21:10 -0500 | [diff] [blame] | 470 | GIT_EDITOR=.git/FAKE_EDITOR |
| 471 | export GIT_EDITOR |
| 472 | exec git commit -a'\'' && |
| 473 | test ! -f .git/index.lock |
Paolo Bonzini | ad5fa3c | 2008-05-29 16:55:53 +0200 | [diff] [blame] | 474 | ' |
| 475 | |
Junio C Hamano | 67bfc03 | 2008-06-02 22:17:42 -0700 | [diff] [blame] | 476 | rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG |
| 477 | git reset -q --hard |
| 478 | |
| 479 | test_expect_success 'Hand committing of a redundant merge removes dups' ' |
| 480 | |
| 481 | git rev-parse second master >expect && |
| 482 | test_must_fail git merge second master && |
| 483 | git checkout master g && |
| 484 | EDITOR=: git commit -a && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 485 | git cat-file commit HEAD >raw && |
| 486 | sed -n -e "s/^parent //p" -e "/^$/q" raw >actual && |
Junio C Hamano | 67bfc03 | 2008-06-02 22:17:42 -0700 | [diff] [blame] | 487 | test_cmp expect actual |
| 488 | |
| 489 | ' |
| 490 | |
Junio C Hamano | e513843 | 2009-11-06 23:06:06 -0800 | [diff] [blame] | 491 | test_expect_success 'A single-liner subject with a token plus colon is not a footer' ' |
| 492 | |
| 493 | git reset --hard && |
| 494 | git commit -s -m "hello: kitty" --allow-empty && |
Denton Liu | 94ca361 | 2019-04-17 11:23:24 +0100 | [diff] [blame] | 495 | git cat-file commit HEAD >raw && |
| 496 | sed -e "1,/^$/d" raw >actual && |
Stefano Lattarini | 3fb0459 | 2012-04-11 13:24:01 +0200 | [diff] [blame] | 497 | test_line_count = 3 actual |
Junio C Hamano | e513843 | 2009-11-06 23:06:06 -0800 | [diff] [blame] | 498 | |
| 499 | ' |
| 500 | |
Brandon Casey | 8c613fd | 2013-02-22 14:05:27 -0800 | [diff] [blame] | 501 | test_expect_success 'commit -s places sob on third line after two empty lines' ' |
| 502 | git commit -s --allow-empty --allow-empty-message && |
| 503 | cat <<-EOF >expect && |
| 504 | |
| 505 | |
| 506 | Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> |
| 507 | |
| 508 | EOF |
| 509 | sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual && |
| 510 | test_cmp expect actual |
| 511 | ' |
| 512 | |
Jeff King | a9ebc43 | 2012-07-26 16:27:55 -0400 | [diff] [blame] | 513 | write_script .git/FAKE_EDITOR <<\EOF |
| 514 | mv "$1" "$1.orig" |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 515 | ( |
| 516 | echo message |
Jeff King | a9ebc43 | 2012-07-26 16:27:55 -0400 | [diff] [blame] | 517 | cat "$1.orig" |
| 518 | ) >"$1" |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 519 | EOF |
| 520 | |
| 521 | echo '## Custom template' >template |
| 522 | |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 523 | try_commit () { |
| 524 | git reset --hard && |
| 525 | echo >>negative && |
| 526 | GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template && |
| 527 | case "$use_template" in |
| 528 | '') |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 529 | test_i18ngrep ! "^## Custom template" .git/COMMIT_EDITMSG ;; |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 530 | *) |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 531 | test_i18ngrep "^## Custom template" .git/COMMIT_EDITMSG ;; |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 532 | esac |
| 533 | } |
| 534 | |
| 535 | try_commit_status_combo () { |
| 536 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 537 | test_expect_success 'commit' ' |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 538 | try_commit "" && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 539 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 540 | ' |
| 541 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 542 | test_expect_success 'commit --status' ' |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 543 | try_commit --status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 544 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 545 | ' |
| 546 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 547 | test_expect_success 'commit --no-status' ' |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 548 | try_commit --no-status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 549 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 550 | ' |
| 551 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 552 | test_expect_success 'commit with commit.status = yes' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 553 | test_config commit.status yes && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 554 | try_commit "" && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 555 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 556 | ' |
| 557 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 558 | test_expect_success 'commit with commit.status = no' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 559 | test_config commit.status no && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 560 | try_commit "" && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 561 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 562 | ' |
| 563 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 564 | test_expect_success 'commit --status with commit.status = yes' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 565 | test_config commit.status yes && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 566 | try_commit --status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 567 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 568 | ' |
| 569 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 570 | test_expect_success 'commit --no-status with commit.status = yes' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 571 | test_config commit.status yes && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 572 | try_commit --no-status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 573 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 574 | ' |
| 575 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 576 | test_expect_success 'commit --status with commit.status = no' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 577 | test_config commit.status no && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 578 | try_commit --status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 579 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 580 | ' |
| 581 | |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 582 | test_expect_success 'commit --no-status with commit.status = no' ' |
Yann Droneaud | e023a31 | 2013-03-24 22:06:14 +0100 | [diff] [blame] | 583 | test_config commit.status no && |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 584 | try_commit --no-status && |
Junio C Hamano | f79ce8d | 2011-04-13 16:17:50 -0700 | [diff] [blame] | 585 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
Junio C Hamano | f9c0181 | 2010-01-13 00:12:54 -0800 | [diff] [blame] | 586 | ' |
| 587 | |
| 588 | } |
| 589 | |
| 590 | try_commit_status_combo |
| 591 | |
| 592 | use_template="-t template" |
| 593 | |
| 594 | try_commit_status_combo |
| 595 | |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 596 | test_expect_success 'commit --status with custom comment character' ' |
Yann Droneaud | 464be63 | 2013-03-24 22:06:10 +0100 | [diff] [blame] | 597 | test_config core.commentchar ";" && |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 598 | try_commit --status && |
| 599 | test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG |
| 600 | ' |
| 601 | |
Nguyễn Thái Ngọc Duy | 84c9dc2 | 2014-05-17 08:52:23 +0700 | [diff] [blame] | 602 | test_expect_success 'switch core.commentchar' ' |
| 603 | test_commit "#foo" foo && |
| 604 | GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend && |
| 605 | test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG |
| 606 | ' |
| 607 | |
| 608 | test_expect_success 'switch core.commentchar but out of options' ' |
| 609 | cat >text <<\EOF && |
| 610 | # 1 |
| 611 | ; 2 |
| 612 | @ 3 |
| 613 | ! 4 |
| 614 | $ 5 |
| 615 | % 6 |
| 616 | ^ 7 |
| 617 | & 8 |
| 618 | | 9 |
| 619 | : 10 |
| 620 | EOF |
| 621 | git commit --amend -F text && |
| 622 | ( |
| 623 | test_set_editor .git/FAKE_EDITOR && |
| 624 | test_must_fail git -c core.commentChar=auto commit --amend |
| 625 | ) |
| 626 | ' |
| 627 | |
Junio C Hamano | b468f0c | 2007-11-22 16:21:49 -0800 | [diff] [blame] | 628 | test_done |