@@ -396,3 +396,118 @@ def test_autosquash_multiline_summary(repo: Repository) -> None:
396396 new = repo .get_commit ("HEAD" )
397397 assert old != new , "commit was modified"
398398 assert old .parents () == new .parents (), "parents are unchanged"
399+
400+
401+ def test_autosquash_multiple_squashes () -> None :
402+ bash (
403+ """
404+ git commit --allow-empty -m 'initial commit'
405+ git commit --allow-empty -m 'target'
406+ git commit --allow-empty --squash :/^target --no-edit
407+ git commit --allow-empty --squash :/^target --no-edit
408+ """
409+ )
410+
411+ with editor_main ([":/^init" , "--autosquash" ], input = b"" ) as ed :
412+ with ed .next_file () as f :
413+ assert f .startswith_dedent (
414+ """\
415+ # This is a combination of 3 commits.
416+ # This is the 1st commit message:
417+
418+ target
419+
420+ # This is the commit message #2:
421+
422+ squash! target
423+
424+ # This is the commit message #3:
425+
426+ squash! target
427+ """
428+ )
429+ f .replace_dedent ("two squashes" )
430+
431+
432+ def test_autosquash_squash_and_fixup () -> None :
433+ bash (
434+ """
435+ git commit --allow-empty -m 'initial commit'
436+ git commit --allow-empty -m 'fixup-target'
437+ git commit --allow-empty --fixup :/^fixup-target --no-edit
438+ git commit --allow-empty -m 'squash-target'
439+ git commit --allow-empty --squash :/^squash-target --no-edit
440+ """
441+ )
442+
443+ with editor_main ([":/^init" , "--autosquash" ], input = b"" ) as ed :
444+ with ed .next_file () as f :
445+ assert f .startswith_dedent (
446+ """\
447+ # This is a combination of 2 commits.
448+ # This is the 1st commit message:
449+
450+ squash-target
451+
452+ # This is the commit message #2:
453+
454+ squash! squash-target
455+ """
456+ )
457+ f .replace_dedent ("squash + fixup" )
458+
459+
460+ def test_autosquash_multiple_squashes_with_fixup () -> None :
461+ bash (
462+ """
463+ git commit --allow-empty -m 'initial commit'
464+ git commit --allow-empty -m 'target'
465+ git commit --allow-empty --squash :/^target --no-edit
466+ git commit --allow-empty --fixup :/^target --no-edit
467+ git commit --allow-empty --squash :/^target --no-edit
468+ git commit --allow-empty -m 'unrelated'
469+ """
470+ )
471+ with editor_main ([":/^init" , "--autosquash" ], input = b"" ) as ed :
472+ with ed .next_file () as f :
473+ assert f .startswith_dedent (
474+ """\
475+ # This is a combination of 4 commits.
476+ # This is the 1st commit message:
477+
478+ target
479+
480+ # This is the commit message #2:
481+
482+ squash! target
483+
484+ # The commit message #3 will be skipped:
485+
486+ # fixup! target
487+
488+ # This is the commit message #4:
489+
490+ squash! target
491+ """
492+ )
493+ f .replace_dedent ("squashes + fixup" )
494+
495+
496+ def test_autosquash_multiple_independent_squashes () -> None :
497+ bash (
498+ """
499+ git commit --allow-empty -m 'initial commit'
500+ git commit --allow-empty -m 'target1'
501+ git commit --allow-empty -m 'target2'
502+ git commit --allow-empty --squash :/^target1 --no-edit
503+ git commit --allow-empty --squash :/^target2 --no-edit
504+ """
505+ )
506+
507+ with editor_main ([":/^init" , "--autosquash" ], input = b"" ) as ed :
508+ with ed .next_file () as f :
509+ assert f .startswith_dedent ("# This is a combination of 2 commits." )
510+ f .replace_dedent ("squash 1" )
511+ with ed .next_file () as f :
512+ assert f .startswith_dedent ("# This is a combination of 2 commits." )
513+ f .replace_dedent ("squash 2" )
0 commit comments