271
test_cmp expect actual
272
'
273
274
+test_expect_success '--reedit-message offers every folded-in message' '
275
+ git reset --hard start &&
276
+ stage_file b &&
277
+ git commit -m "re-one subject" -m "re-one body line" &&
278
+ test_commit --no-tag re-two file c &&
279
+ test_commit re-three file d &&
280
+
281
+ write_script editor <<-\EOF &&
282
+ cat "$1" >edited &&
283
+ echo combined >"$1"
284
+ EOF
285
+ test_set_editor "$(pwd)/editor" &&
286
+ git history squash --reedit-message start.. &&
287
+
288
+ cat >expect <<-EOF &&
289
+ # This is a combination of 3 commits.
290
+ # This is the 1st commit message:
291
+
292
+ re-one subject
293
+
294
+ re-one body line
295
+
296
+ # This is the commit message #2:
297
+
298
+ re-two
299
+
300
+ # This is the commit message #3:
301
+
302
+ re-three
303
+
304
+ # Please enter the commit message for the squash changes. Lines starting
305
+ # with ${SQ}#${SQ} will be ignored, and an empty message aborts the commit.
306
+ # Changes to be committed:
307
+ # modified: file
308
+ #
309
+ EOF
310
+ test_cmp expect edited &&
311
+ check_log_subjects -1 <<-\EOF
312
+ combined
313
+ EOF
314
+'
315
+
316
+test_expect_success '--reedit-message handles fixup!, squash! and amend! like rebase' '
317
+ git reset --hard start &&
318
+ test_commit --no-tag mark-base file b &&
319
+ stage_file c &&
320
+ commit_with_message "fixup! mark-base\n\nfixup body\n" &&
321
+ stage_file d &&
322
+ commit_with_message "squash! mark-base\n\nsquash remark\n" &&
323
+ stage_file e &&
324
+ commit_with_message "amend! mark-base\n\namended message\n" &&
325
+
326
+ write_script editor <<-\EOF &&
327
+ cat "$1" >edited
328
+ EOF
329
+ test_set_editor "$(pwd)/editor" &&
330
+ git history squash --reedit-message start.. &&
331
+
332
+ cat >expect <<-EOF &&
333
+ # This is a combination of 4 commits.
334
+ # This is the 1st commit message:
335
+
336
+ mark-base
337
+
338
+ # The commit message #2 will be skipped:
339
+
340
+ # fixup! mark-base
341
+ #
342
+ # fixup body
343
+
344
+ # This is the commit message #3:
345
+
346
+ # squash! mark-base
347
+
348
+ squash remark
349
+
350
+ # This is the commit message #4:
351
+
352
+ # amend! mark-base
353
+
354
+ amended message
355
+
356
+ # Please enter the commit message for the squash changes. Lines starting
357
+ # with ${SQ}#${SQ} will be ignored, and an empty message aborts the commit.
358
+ # Changes to be committed:
359
+ # modified: file
360
+ #
361
+ EOF
362
+ test_cmp expect edited &&
363
+ check_log_messages -1 <<-\EOF
364
+ mark-base
365
+
366
+ squash remark
367
+
368
+ amended message
369
+
370
+ EOF
371
+'
372
+
373
+test_expect_success '--reedit-message groups fixups under their targets' '
374
+ git reset --hard start &&
375
+ test_commit --no-tag alpha file a1 &&
376
+ test_commit --no-tag beta file b1 &&
377
+ stage_file a2 &&
378
+ commit_with_message "fixup! alpha\n" &&
379
+ stage_file b2 &&
380
+ commit_with_message "fixup! beta\n" &&
381
+
382
+ write_script editor <<-\EOF &&
383
+ cat "$1" >edited
384
+ EOF
385
+ test_set_editor "$(pwd)/editor" &&
386
+ git history squash --reedit-message start.. &&
387
+
388
+ cat >expect <<-EOF &&
389
+ # This is a combination of 4 commits.
390
+ # This is the 1st commit message:
391
+
392
+ alpha
393
+
394
+ # The commit message #2 will be skipped:
395
+
396
+ # fixup! alpha
397
+
398
+ # This is the commit message #3:
399
+
400
+ beta
401
+
402
+ # The commit message #4 will be skipped:
403
+
404
+ # fixup! beta
405
+
406
+ # Please enter the commit message for the squash changes. Lines starting
407
+ # with ${SQ}#${SQ} will be ignored, and an empty message aborts the commit.
408
+ # Changes to be committed:
409
+ # modified: file
410
+ #
411
+ EOF
412
+ test_cmp expect edited
413
+'
414
+
415
+test_expect_success '--reedit-message lets amend! replace its target message' '
416
+ git reset --hard start &&
417
+ test_commit --no-tag mark-base file b &&
418
+ stage_file c &&
419
+ commit_with_message "amend! mark-base\n\namended message\n" &&
420
+ stage_file d &&
421
+ commit_with_message "squash! mark-base\n\nsquash remark\n" &&
422
+
423
+ write_script editor <<-\EOF &&
424
+ cat "$1" >edited
425
+ EOF
426
+ test_set_editor "$(pwd)/editor" &&
427
+ git history squash --reedit-message start.. &&
428
+
429
+ cat >expect <<-EOF &&
430
+ # This is a combination of 3 commits.
431
+ # The 1st commit message will be skipped:
432
+
433
+ # mark-base
434
+
435
+ # This is the commit message #2:
436
+
437
+ # amend! mark-base
438
+
439
+ amended message
440
+
441
+ # This is the commit message #3:
442
+
443
+ # squash! mark-base
444
+
445
+ squash remark
446
+
447
+ # Please enter the commit message for the squash changes. Lines starting
448
+ # with ${SQ}#${SQ} will be ignored, and an empty message aborts the commit.
449
+ # Changes to be committed:
450
+ # modified: file
451
+ #
452
+ EOF
453
+ test_cmp expect edited &&
454
+ check_log_messages -1 <<-\EOF
455
+ amended message
456
+
457
+ squash remark
458
+
459
+ EOF
460
+'
461
+
462
+test_expect_success '--reedit-message aborts on an empty message' '
463
+ git reset --hard three &&
464
+ head_before=$(git rev-parse HEAD) &&
465
+
466
+ write_script editor <<-\EOF &&
467
+ >"$1"
468
+ EOF
469
+ test_set_editor "$(pwd)/editor" &&
470
+ test_must_fail git history squash --reedit-message start.. &&
471
+
472
+ test_cmp_rev "$head_before" HEAD
473
+'
474
+
475
test_expect_success '--update-refs=head only moves HEAD' '
476
git reset --hard three &&
477
git branch -f other HEAD &&