Skip to content

Commit 52125b0

Browse files
fix(split): don't unhide obsolete children
1 parent e16f597 commit 52125b0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

git-branchless/src/commands/split.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ pub fn split(
530530
builder.move_subtree(target_oid, vec![remainder_commit_oid])?
531531
} else {
532532
let children = dag.query_children(CommitSet::from(target_oid))?;
533+
let children = dag.filter_visible_commits(children)?;
533534
for child in dag.commit_set_to_vec(&children)? {
534535
match (&split_mode, extracted_commit_oid) {
535536
(_, None) | (SplitMode::DetachAfter, Some(_)) => {

git-branchless/tests/test_split.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)