Skip to content

Commit dca26ed

Browse files
committed
split: the second commit keeps the change id
The first commit contains the split out changes. The second commit usually keeps most of the changes, the change id and the attached bookmarks (as long as split.legacy-bookmark-behavior is true, which should stay the default value). This no-implicit-move behavior aligns with other jj commands. With the -A/-B/-d options, the split-out commit may be moved anywhere. With commit tree @ pmpklomk (empty) (no description set) ○ pzskstlk *letters* fileB ○ kmvzrqtu fileA │ ○ lyzvpymy *numbers* file3&C │ ○ kpmxxkwk file2 │ ○ xzvtlrrt file1 ├─╯ ◆ zzzzzzzz root() when splitting `fileC` out of `lyzvpymy` to the other branch with jj split -r lyzvpymy -d pzskstlk the change id and the bookmark stay in the branch with the source commit. @ pmpklomk (empty) (no description set) ○ vowztxqo fileC ○ pzskstlk *letters* fileB ○ kmvzrqtu fileA │ ○ lyzvpymy *numbers* file3 │ ○ kpmxxkwk file2 │ ○ xzvtlrrt file1 ├─╯ ◆ zzzzzzzz root()
1 parent b592d61 commit dca26ed

File tree

5 files changed

+141
-137
lines changed

5 files changed

+141
-137
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4343
* Added `git.track-default-bookmark-on-clone` setting to control whether to
4444
track the default remote bookmark on `jj git clone`.
4545

46+
* `jj split` assigns the change id and the bookmarks of the source revision
47+
to the second revision.
48+
You can opt out of this change by setting `split.legacy-bookmark-behavior = true`,
49+
but this will likely be removed in a future release.
50+
4651
### Fixed bugs
4752

4853
* Work around a git issue that could cause subprocess operations to hang if the

cli/src/commands/split.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ use crate::ui::Ui;
4949
///
5050
/// Starts a [diff editor] on the changes in the revision. Edit the right side
5151
/// of the diff until it has the content you want in the new revision. Once
52-
/// you close the editor, your edited content will replace the previous
53-
/// revision. The remaining changes will be put in a new revision on top.
52+
/// you close the editor, your edited content will be put in a new revision
53+
/// before the original revision, while the remaining changes will replace the
54+
/// original revision.
5455
///
5556
/// [diff editor]:
5657
/// https://jj-vcs.github.io/jj/latest/config/#editing-diffs
@@ -219,11 +220,14 @@ pub(crate) fn cmd_split(
219220
// Prompt the user to select the changes they want for the first commit.
220221
let target = select_diff(ui, &tx, &target_commit, &matcher, &diff_selector)?;
221222

223+
let legacy_bookmark_behavior =
224+
!use_move_flags && tx.settings().get_bool("split.legacy-bookmark-behavior")?;
225+
222226
// Create the first commit, which includes the changes selected by the user.
223227
let first_commit = {
224228
let mut commit_builder = tx.repo_mut().rewrite_commit(&target.commit).detach();
225229
commit_builder.set_tree_id(target.selected_tree.id());
226-
if use_move_flags {
230+
if !legacy_bookmark_behavior {
227231
commit_builder
228232
// Generate a new change id so that the commit being split doesn't
229233
// become divergent.
@@ -274,7 +278,7 @@ pub(crate) fn cmd_split(
274278
commit_builder
275279
.set_parents(parents)
276280
.set_tree_id(new_tree.id());
277-
if !use_move_flags {
281+
if legacy_bookmark_behavior {
278282
commit_builder
279283
// Generate a new change id so that the commit being split doesn't
280284
// become divergent.
@@ -415,14 +419,9 @@ fn rewrite_descendants(
415419
tx.repo_mut()
416420
.transform_descendants(vec![target.commit.id().clone()], |mut rewriter| {
417421
num_rebased += 1;
418-
if parallel && legacy_bookmark_behavior {
419-
// The old_parent is the second commit due to the rewrite above.
422+
if parallel {
420423
rewriter
421424
.replace_parent(second_commit.id(), [first_commit.id(), second_commit.id()]);
422-
} else if parallel {
423-
rewriter.replace_parent(first_commit.id(), [first_commit.id(), second_commit.id()]);
424-
} else {
425-
rewriter.replace_parent(first_commit.id(), [second_commit.id()]);
426425
}
427426
rewriter.rebase()?.write()?;
428427
Ok(())

cli/src/config/misc.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ auto-update-stale = false
5555
# The behavior when this flag is set to false is experimental and may be changed
5656
# in the future.
5757
[split]
58-
legacy-bookmark-behavior = true
58+
legacy-bookmark-behavior = false

cli/tests/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2442,7 +2442,7 @@ For example, if all you need is the `README.md` and the `lib/` directory, use `j
24422442

24432443
Split a revision in two
24442444

2445-
Starts a [diff editor] on the changes in the revision. Edit the right side of the diff until it has the content you want in the new revision. Once you close the editor, your edited content will replace the previous revision. The remaining changes will be put in a new revision on top.
2445+
Starts a [diff editor] on the changes in the revision. Edit the right side of the diff until it has the content you want in the new revision. Once you close the editor, your edited content will be put in a new revision before the original revision, while the remaining changes will replace the original revision.
24462446

24472447
[diff editor]: https://jj-vcs.github.io/jj/latest/config/#editing-diffs
24482448

0 commit comments

Comments
 (0)