Skip to content

Commit e58b7ad

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. 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 5361935 commit e58b7ad

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
@@ -53,6 +53,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5353
* Templates can now do arithmetic on integers with the `+`, `-`, `*`, `/`, and `%`
5454
infix operators.
5555

56+
* `jj split` assigns the change id and the bookmarks of the source revision
57+
to the revision with the non-selected changes.
58+
You can opt out of this change by setting `split.legacy-bookmark-behavior = true`,
59+
but this will likely be removed in a future release.
60+
5661
### Fixed bugs
5762

5863
* 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
@@ -54,4 +54,4 @@ auto-update-stale = false
5454
# The behavior when this flag is set to false is experimental and may be changed
5555
# in the future.
5656
[split]
57-
legacy-bookmark-behavior = true
57+
legacy-bookmark-behavior = false

cli/tests/[email protected]

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

24592459
Split a revision in two
24602460

2461-
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.
2461+
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.
24622462

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

0 commit comments

Comments
 (0)