Skip to content

Commit 735d4b8

Browse files
temp(move --fixup): Try to get on-disk rebase working
1 parent fe10f7c commit 735d4b8

File tree

3 files changed

+95
-102
lines changed

3 files changed

+95
-102
lines changed

git-branchless-lib/src/core/rewrite/execute.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ mod in_memory {
609609
Some(MaybeZeroOid::NonZero(rewritten_oid)) => repo
610610
.find_commit_or_fail(*rewritten_oid)
611611
.wrap_err("Finding commit to apply")?,
612-
Some(MaybeZeroOid::Zero) => todo!("FIXME fixing up deleted commit"),
612+
Some(MaybeZeroOid::Zero) => {
613+
todo!("FIXME fixing up deleted commit: {:#?}", command)
614+
}
613615
None => repo
614616
.find_commit_or_fail(*commit_to_fixup_oid)
615617
.wrap_err("Finding commit to apply")?,
@@ -700,6 +702,7 @@ mod in_memory {
700702
*commit_to_fixup_oid,
701703
MaybeZeroOid::NonZero(rebased_commit_oid),
702704
);
705+
// FIXME can this be removed if we use RebaseCommand::SkipUpstreamBlahBlah?
703706
rewritten_oids.insert(
704707
*fixup_commit_oid,
705708
match head_oid {
@@ -1051,7 +1054,17 @@ mod on_disk {
10511054
)
10521055
.wrap_err_with(|| format!("Writing head-name to: {:?}", &head_name_file_path))?;
10531056

1054-
save_original_head_info(repo, &head_info)?;
1057+
// Do not save head info if head is being fixed up. We want to
1058+
// figure out which commit to checkout later.
1059+
if !rebase_plan.commands.iter().any(|command| match command {
1060+
RebaseCommand::FixUp {
1061+
commit_to_fixup_oid,
1062+
fixup_commit_oid: _,
1063+
} => commit_to_fixup_oid == &head_oid,
1064+
_ => false,
1065+
}) {
1066+
save_original_head_info(repo, &head_info)?;
1067+
}
10551068

10561069
// Dummy `head` file. We will `reset` to the appropriate commit as soon as
10571070
// we start the rebase.

git-branchless-lib/src/core/rewrite/plan.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,12 @@ impl<'a> RebasePlanBuilder<'a> {
841841
Some(commit_to_fixup_oid) => {
842842
acc.push(RebaseCommand::FixUp {
843843
commit_to_fixup_oid: *commit_to_fixup_oid,
844-
fixup_commit_oid: commit_oid, // or original_commit_oid?
844+
fixup_commit_oid: commit_oid,
845+
});
846+
// FIXME is this right? It seems to help for on disk
847+
// rebase w/ fixup, but not for multiple fixups
848+
acc.push(RebaseCommand::SkipUpstreamAppliedCommit {
849+
commit_oid: *commit_to_fixup_oid,
845850
});
846851
}
847852
None => acc.push(RebaseCommand::Pick {

git-branchless/tests/command/test_move.rs

Lines changed: 74 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4575,7 +4575,8 @@ fn test_move_fixup_head_into_parent() -> eyre::Result<()> {
45754575
])?;
45764576
insta::assert_snapshot!(stdout, @r###"
45774577
Attempting rebase in-memory...
4578-
[1/1] Amended as: 68aa706 create test2.txt
4578+
[1/2] Amended as: 68aa706 create test2.txt
4579+
[2/2] Skipped commit (was already applied upstream): 96d1c37 create test2.txt
45794580
branchless: processing 2 rewritten commits
45804581
branchless: running command: <git-executable> checkout 68aa7060ef38274a33c9a51dc6964de6e84fbd43
45814582
O f777ecc (master) create initial.txt
@@ -4622,29 +4623,20 @@ fn test_move_fixup_parent_into_head() -> eyre::Result<()> {
46224623
"###);
46234624

46244625
// --on-disk
4625-
// FIXME on disk is not working :(
4626-
// {
4627-
// let git = git.duplicate_repo()?;
4628-
// git.run(&[
4629-
// "move",
4630-
// "--on-disk",
4631-
// "--fixup",
4632-
// "--debug-dump-rebase-plan",
4633-
// "-x",
4634-
// &test2_oid.to_string(),
4635-
// "-d",
4636-
// &"HEAD".to_string(),
4637-
// ])?;
4638-
4639-
// let (stdout, _stderr) = git.run(&["smartlog"])?;
4640-
// insta::assert_snapshot!(stdout, @r###"
4641-
// O f777ecc (master) create initial.txt
4642-
// |
4643-
// o 62fc20d create test1.txt
4644-
// |
4645-
// @ 68aa706 create test3.txt
4646-
// "###);
4647-
// }
4626+
{
4627+
let git = git.duplicate_repo()?;
4628+
let (_stdout, _stderr) =
4629+
git.run(&["move", "--on-disk", "--fixup", "-x", &test2_oid.to_string()])?;
4630+
4631+
let (stdout, _stderr) = git.run(&["smartlog"])?;
4632+
insta::assert_snapshot!(stdout, @r###"
4633+
O f777ecc (master) create initial.txt
4634+
|
4635+
o 62fc20d create test1.txt
4636+
|
4637+
@ 2565373 create test3.txt
4638+
"###);
4639+
}
46484640

46494641
// --in-memory
46504642
{
@@ -4660,8 +4652,9 @@ fn test_move_fixup_parent_into_head() -> eyre::Result<()> {
46604652
// insta::assert_snapshot!(stderr, @r###""###);
46614653
insta::assert_snapshot!(stdout, @r###"
46624654
Attempting rebase in-memory...
4663-
[1/2] Committed as: 4838e49 create test3.txt
4664-
[2/2] Amended as: 2565373 create test3.txt
4655+
[1/3] Committed as: 4838e49 create test3.txt
4656+
[2/3] Amended as: 2565373 create test3.txt
4657+
[3/3] Skipped commit (was already applied upstream): 70deb1e create test3.txt
46654658
branchless: processing 2 rewritten commits
46664659
branchless: running command: <git-executable> checkout 2565373efecda4dda6274ad5107dbff6be05f0a3
46674660
O f777ecc (master) create initial.txt
@@ -4704,29 +4697,25 @@ fn test_move_fixup_multiple_into_ancestor() -> eyre::Result<()> {
47044697
"###);
47054698

47064699
// --on-disk
4707-
// FIXME on disk is not working :(
4708-
// {
4709-
// let git = git.duplicate_repo()?;
4710-
// git.run(&[
4711-
// "move",
4712-
// "--on-disk",
4713-
// "--fixup",
4714-
// "--debug-dump-rebase-plan",
4715-
// "-x",
4716-
// &test2_oid.to_string(),
4717-
// "-d",
4718-
// &"HEAD".to_string(),
4719-
// ])?;
4720-
4721-
// let (stdout, _stderr) = git.run(&["smartlog"])?;
4722-
// insta::assert_snapshot!(stdout, @r###"
4723-
// O f777ecc (master) create initial.txt
4724-
// |
4725-
// o 62fc20d create test1.txt
4726-
// |
4727-
// @ 68aa706 create test3.txt
4728-
// "###);
4729-
// }
4700+
{
4701+
let git = git.duplicate_repo()?;
4702+
git.run(&[
4703+
"move",
4704+
"--on-disk",
4705+
"--fixup",
4706+
"-x",
4707+
"HEAD+HEAD~",
4708+
"-d",
4709+
&test1_oid.to_string(),
4710+
])?;
4711+
4712+
let (stdout, _stderr) = git.run(&["smartlog"])?;
4713+
insta::assert_snapshot!(stdout, @r###"
4714+
O f777ecc (master) create initial.txt
4715+
|
4716+
@ 9ede80c create test1.txt
4717+
"###);
4718+
}
47304719

47314720
// --in-memory
47324721
{
@@ -4785,29 +4774,16 @@ fn test_move_fixup_multiple_ancestors_into_head() -> eyre::Result<()> {
47854774
"###);
47864775

47874776
// --on-disk
4788-
// FIXME on disk is not working :(
4789-
// {
4790-
// let git = git.duplicate_repo()?;
4791-
// git.run(&[
4792-
// "move",
4793-
// "--on-disk",
4794-
// "--fixup",
4795-
// "--debug-dump-rebase-plan",
4796-
// "-x",
4797-
// &test2_oid.to_string(),
4798-
// "-d",
4799-
// &"HEAD".to_string(),
4800-
// ])?;
4801-
4802-
// let (stdout, _stderr) = git.run(&["smartlog"])?;
4803-
// insta::assert_snapshot!(stdout, @r###"
4804-
// O f777ecc (master) create initial.txt
4805-
// |
4806-
// o 62fc20d create test1.txt
4807-
// |
4808-
// @ 68aa706 create test3.txt
4809-
// "###);
4810-
// }
4777+
{
4778+
let git = git.duplicate_repo()?;
4779+
git.run(&["move", "--on-disk", "--fixup", "-x", "HEAD~+HEAD~2"])?;
4780+
let (stdout, _stderr) = git.run(&["smartlog"])?;
4781+
insta::assert_snapshot!(stdout, @r###"
4782+
O f777ecc (master) create initial.txt
4783+
|
4784+
@ dbc9c34 create test3.txt
4785+
"###);
4786+
}
48114787

48124788
// --in-memory
48134789
{
@@ -4873,33 +4849,32 @@ fn test_move_fixup_complicated() -> eyre::Result<()> {
48734849
"###);
48744850

48754851
// --on-disk
4876-
// FIXME on disk is not working :(
4877-
// {
4878-
// let git = git.duplicate_repo()?;
4879-
// git.run(&[
4880-
// "move",
4881-
// "--on-disk",
4882-
// "--fixup",
4883-
// "-x",
4884-
// &format!("{}+{}", test2_oid, test6_oid),
4885-
// "-d",
4886-
// &test4_oid.to_string(),
4887-
// ])?;
4888-
// let (stdout, _stderr) = git.run(&["smartlog"])?;
4889-
// insta::assert_snapshot!(stdout, @r###"
4890-
// O f777ecc (master) create initial.txt
4891-
// |
4892-
// o 62fc20d create test1.txt
4893-
// |
4894-
// o 4838e49 create test3.txt
4895-
// |\
4896-
// | o 9866190 create test4.txt
4897-
// | |
4898-
// | o a84ae82 create test5.txt
4899-
// |
4900-
// @ dd38f3d create test7.txt
4901-
// "###);
4902-
// }
4852+
{
4853+
let git = git.duplicate_repo()?;
4854+
git.run(&[
4855+
"move",
4856+
"--on-disk",
4857+
"--fixup",
4858+
"-x",
4859+
&format!("{}+{}", test2_oid, test6_oid),
4860+
"-d",
4861+
&test4_oid.to_string(),
4862+
])?;
4863+
let (stdout, _stderr) = git.run(&["smartlog"])?;
4864+
insta::assert_snapshot!(stdout, @r###"
4865+
O f777ecc (master) create initial.txt
4866+
|
4867+
o 62fc20d create test1.txt
4868+
|
4869+
o 4838e49 create test3.txt
4870+
|\
4871+
| o 9866190 create test4.txt
4872+
| |
4873+
| o a84ae82 create test5.txt
4874+
|
4875+
@ dd38f3d create test7.txt
4876+
"###);
4877+
}
49034878

49044879
// --in-memory
49054880
{

0 commit comments

Comments
 (0)