-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix rebase -r
of a parent of a merge commit
#538
Conversation
a0da62a
to
9717fd1
Compare
I think I figured out my original problem, but it uncovered another problem (see below). I don't have the energy to figure out the new problem today, though.
|
Actually, I could argue that the last change to the test is desired behavior. WDYT? I changed the test, so the tests now pass. |
9717fd1
to
3831033
Compare
3831033
to
e2b792d
Compare
Yep, that looks much better. Maybe I was too confident that it worked correctly before so I didn't look carefully enough before accepting the current output. Thanks for the fix! I'll take a look at the code later. I just wanted to share that I think the change to the test makes sense. |
e2b792d
to
8d1fe29
Compare
Previously, using `rebase -r` on the parent of a merge commit turned it into a non-merge commit. In other words, starting with ``` o d |\ o | c o | b | o a |/ o ``` and doing `rebase -r c -d a` resulted in ``` o d o b | o c | o a |/ o ``` where `d` is no longer a merge commit. For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass): ``` #[test] fn test_rebase_single_revision_merge_parent() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); create_commit(&test_env, &repo_path, "a", &[]); create_commit(&test_env, &repo_path, "b", &[]); create_commit(&test_env, &repo_path, "c", &["b"]); create_commit(&test_env, &repo_path, "d", &["a", "c"]); // Test the setup insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ o d |\ o | c o | b | o a |/ o "###); let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]); insta::assert_snapshot!(stdout, @r###" Also rebased 2 descendant commits onto parent of rebased commit Working copy now at: 3e176b54d680 (no description set) Added 0 files, modified 0 files, removed 2 files "###); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ o d | o c o | b | o a |/ o "###); } ```
8d1fe29
to
67738a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks again.
Thank you for the quick review! |
I realized that the logic I added here should be identical to a large piece of I think that the operation "rebase all the children of X onto parents of X, without losing the other parents of the children" could be factored out into a function.
|
Yes, that's what I meant (in https://github.com/martinvonz/jj/pull/538/files#r967986097). The common code lives in https://github.com/martinvonz/jj/blob/main/lib/src/rewrite.rs. That code knows how to move commits on top of rewritten commits and to updates branches accordingly. It also knows how to rebase children onto parents of abandoned commits, and to updated branches to the parents of abandoned commits. However, |
…ct and indirect descendants This is similar to the following test: https://github.com/martinvonz/jj/blob/5186066cf5064564466e58096b79fba6b0c0ecfd/cli/tests/test_rebase_command.rs#L264-L269 from martinvonz#538.
…ect descendants This is similar to the following test: https://github.com/martinvonz/jj/blob/5186066cf5064564466e58096b79fba6b0c0ecfd/cli/tests/test_rebase_command.rs#L264-L269 from martinvonz#538.
…ect descendants This is similar to the following test: https://github.com/martinvonz/jj/blob/5186066cf5064564466e58096b79fba6b0c0ecfd/cli/tests/test_rebase_command.rs#L264-L269 from #538.
Comments
(UPDATE: I deleted some no-longer relevant info from this comment)
This is a fix to a bug in
rebase -r
described below. It also changes the behavior of another rebase test in a way that seems desired to me.I'm not friends with Rust yet, so I'm sure the style is not great.
Feel free to just use the test I wrote in here if you prefer a different fix.
PR Description
Previously, using
rebase -r
on the parent of a merge committurned it into a non-merge commit. In other words, starting
with
and doing
rebase -r c -d a
resulted inwhere
d
is no longer a merge commit.For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):