@@ -1394,3 +1394,79 @@ fn test_split_will_not_split_to_empty_commit() -> eyre::Result<()> {
13941394
13951395 Ok ( ( ) )
13961396}
1397+
1398+ #[ test]
1399+ fn test_split_does_not_unhide_obsolete_children ( ) -> eyre:: Result < ( ) > {
1400+ let git = make_git ( ) ?;
1401+ git. init_repo ( ) ?;
1402+ git. detach_head ( ) ?;
1403+
1404+ {
1405+ // Create test1.txt and test2.txt in a single commit
1406+ git. write_file_txt ( "test1" , "contents1" ) ?;
1407+ git. write_file_txt ( "test2" , "contents2" ) ?;
1408+ git. run ( & [ "add" , "." ] ) ?;
1409+ git. run ( & [ "commit" , "-m" , "first commit" ] ) ?;
1410+
1411+ // Create a third file in "second commit"
1412+ git. write_file_txt ( "test3" , "contents3" ) ?;
1413+ git. run ( & [ "add" , "." ] ) ?;
1414+ git. run ( & [ "commit" , "-m" , "second commit" ] ) ?;
1415+
1416+ // verify initial state
1417+ let ( stdout, _stderr) = git. branchless ( "smartlog" , & [ ] ) ?;
1418+ insta:: assert_snapshot!( & stdout, @r###"
1419+ O f777ecc (master) create initial.txt
1420+ |
1421+ o 4d11d02 first commit
1422+ |
1423+ @ 61d094b second commit
1424+ "### ) ;
1425+ }
1426+
1427+ {
1428+ // amend the current commit in some way
1429+ git. write_file_txt ( "test2" , "updated2" ) ?;
1430+ git. branchless ( "amend" , & [ ] ) ?;
1431+
1432+ let ( stdout, _stderr) = git. branchless ( "smartlog" , & [ ] ) ?;
1433+ insta:: assert_snapshot!( & stdout, @r###"
1434+ O f777ecc (master) create initial.txt
1435+ |
1436+ o 4d11d02 first commit
1437+ |
1438+ @ 6698c7b second commit
1439+ "### ) ;
1440+ }
1441+
1442+ {
1443+ // Split the first commit (HEAD~) by extracting test2.txt
1444+ // This will rebase children onto the split result.
1445+ // There should be only 1 child. split should not unhide previously
1446+ // hidden/rewritten/obsolete commits.
1447+ let ( stdout, _stderr) = git. branchless ( "split" , & [ "HEAD~" , "test2.txt" ] ) ?;
1448+ insta:: assert_snapshot!( & stdout, @r###"
1449+ Attempting rebase in-memory...
1450+ [1/1] Committed as: ae95d4c second commit
1451+ branchless: processing 1 rewritten commit
1452+ branchless: running command: <git-executable> checkout ae95d4c54730973107527df675e53de5aec4f855 --
1453+ In-memory rebase succeeded.
1454+ O f777ecc (master) create initial.txt
1455+ |
1456+ o 8e5c74b first commit
1457+ |
1458+ o a55d783 temp(split): test2.txt (+1)
1459+ |
1460+ @ ae95d4c second commit
1461+ "### ) ;
1462+
1463+ let ( stdout, _stderr) = git. run ( & [ "show" , "--pretty=format:" , "--stat" , "HEAD" ] ) ?;
1464+ insta:: assert_snapshot!( & stdout, @"
1465+ test2.txt | 2 +-
1466+ test3.txt | 1 +
1467+ 2 files changed, 2 insertions(+), 1 deletion(-)
1468+ " ) ;
1469+ }
1470+
1471+ Ok ( ( ) )
1472+ }
0 commit comments