···11661166 let output = work_dir.run_jj(["squash", "--from=a", "--into=b", "--restore-descendants"]);
11671167 insta::assert_snapshot!(output, @r"
11681168 ------- stderr -------
11691169- Rebased 2 descendant commits (while preserving their content)
11701170- Working copy (@) now at: kpqxywon 7fa445c9 f | (no description set)
11691169+ Rebased 5 descendant commits (while preserving their content)
11701170+ Working copy (@) now at: kpqxywon 27d75f43 f | (no description set)
11711171 Parent commit (@-) : yostqsxw 102e6106 e | (no description set)
11721172- Parent commit (@-) : mzvwutvl a2ff7c27 c | (no description set)
11721172+ Parent commit (@-) : mzvwutvl 86d2ecde c | (no description set)
11731173 [EOF]
11741174 ");
11751175 insta::assert_snapshot!(run_log(), @r"
11761176- @ 7fa445c9e606 f
11761176+ @ 27d75f43e860 f
11771177 ├─╮ A f
11781178- │ ○ a2ff7c27dbba c
11781178+ │ ○ 86d2ecdec2d7 c
11791179 │ │ A c
11801180- │ ○ 2bf81678391c b
11801180+ │ ○ 7c3b32b0545d b
11811181 │ │ A a
11821182 │ │ A b
11831183 ○ │ 102e61065eb2 e
···12221222 ]);
12231223 insta::assert_snapshot!(output, @r"
12241224 ------- stderr -------
12251225- Rebased 2 descendant commits (while preserving their content)
12261226- Working copy (@) now at: kpqxywon 30c1ec1b f | (no description set)
12251225+ Rebased 5 descendant commits (while preserving their content)
12261226+ Working copy (@) now at: kpqxywon a6c6eeb5 f | (no description set)
12271227 Parent commit (@-) : yostqsxw c20a2a7a e | (no description set)
12281228- Parent commit (@-) : mzvwutvl 601223f5 c | (no description set)
12281228+ Parent commit (@-) : mzvwutvl 5230f5a0 c | (no description set)
12291229 [EOF]
12301230 ");
12311231 insta::assert_snapshot!(run_log(), @r"
12321232- @ 30c1ec1b6264 f
12321232+ @ a6c6eeb5767f f
12331233 ├─╮ A f
12341234- │ ○ 601223f5faa8 c
12341234+ │ ○ 5230f5a06e69 c
12351235 │ │ A c
12361236- │ ○ 28223a4af36c b
12361236+ │ ○ 5d6fef1e0e34 b
12371237 │ │ A a
12381238 │ │ A b
12391239 ○ │ c20a2a7a24ba e
···14741474 let output = work_dir.run_jj(["squash", "--from=a", "--into=e", "--restore-descendants"]);
14751475 insta::assert_snapshot!(output, @r"
14761476 ------- stderr -------
14771477- Rebased 1 descendant commits (while preserving their content)
14781478- Working copy (@) now at: kpqxywon 94ad7042 f | (no description set)
14791479- Parent commit (@-) : yostqsxw 582d640e e | (no description set)
14771477+ Rebased 5 descendant commits (while preserving their content)
14781478+ Working copy (@) now at: kpqxywon e92b3f0f f | (no description set)
14791479+ Parent commit (@-) : yostqsxw 78651b37 e | (no description set)
14801480 Parent commit (@-) : mzvwutvl 2214436c c | (no description set)
14811481 [EOF]
14821482 ");
14831483 insta::assert_snapshot!(run_log(), @r"
14841484- @ 94ad70428c4a f
14841484+ @ e92b3f0fb9fe f
14851485 ├─╮ A f
14861486 │ ○ 2214436c3fa7 c
14871487 │ │ A c
14881488 │ ○ a469c893f362 b
14891489 │ │ A a
14901490 │ │ A b
14911491- ○ │ 582d640e331f e
14911491+ ○ │ 78651b37e114 e
14921492 │ │ A e
14931493 ○ │ 93671eb30330 d
14941494 ├─╯ A a
+16-23
lib/src/rewrite.rs
···11701170 }
1171117111721172 let mut rewritten_destination = destination.clone();
11731173- if sources.iter().any(|source| {
11741174- repo.index()
11751175- .is_ancestor(source.commit.id(), destination.id())
11761176- }) {
11731173+ if !restore_descendants
11741174+ && sources.iter().any(|source| {
11751175+ repo.index()
11761176+ .is_ancestor(source.commit.id(), destination.id())
11771177+ })
11781178+ {
11771179 // If we're moving changes to a descendant, first rebase descendants onto the
11781180 // rewritten sources. Otherwise it will likely already have the content
11791181 // changes we're moving, so applying them will have no effect and the
11801182 // changes will disappear.
11811181- if restore_descendants {
11821182- repo.reparent_descendants_with_progress(|old_commit, rebased_commit| {
11831183- if old_commit.id() != destination.id() {
11841184- return;
11851185- }
11861186- rewritten_destination = rebased_commit;
11871187- })?;
11881188- } else {
11891189- let options = RebaseOptions::default();
11901190- repo.rebase_descendants_with_options(&options, |old_commit, rebased_commit| {
11911191- if old_commit.id() != destination.id() {
11921192- return;
11931193- }
11941194- rewritten_destination = match rebased_commit {
11951195- RebasedCommit::Rewritten(commit) => commit,
11961196- RebasedCommit::Abandoned { .. } => panic!("all commits should be kept"),
11971197- };
11981198- })?;
11991199- }
11831183+ let options = RebaseOptions::default();
11841184+ repo.rebase_descendants_with_options(&options, |old_commit, rebased_commit| {
11851185+ if old_commit.id() != destination.id() {
11861186+ return;
11871187+ }
11881188+ rewritten_destination = match rebased_commit {
11891189+ RebasedCommit::Rewritten(commit) => commit,
11901190+ RebasedCommit::Abandoned { .. } => panic!("all commits should be kept"),
11911191+ };
11921192+ })?;
12001193 }
12011194 // Apply the selected changes onto the destination
12021195 let mut destination_tree = rewritten_destination.tree()?;