Skip to content

Commit 9f1da45

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 dc61eb3 commit 9f1da45

File tree

5 files changed

+214
-157
lines changed

5 files changed

+214
-157
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8585
anywhere in the revision tree with the `--insert-before`, `--insert-after` and
8686
`--destination` command line flags.
8787

88+
* `jj split` assigns the change id of the source revision to the second revision.
89+
You can opt out of this change by setting `split.legacy-change-id-behavior = true`,
90+
but this will likely be removed in a future release.
91+
8892
### Fixed bugs
8993

9094
* Fixed crash on change-delete conflict resolution.

cli/src/commands/split.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,17 @@ pub(crate) fn cmd_split(
221221
// Prompt the user to select the changes they want for the first commit.
222222
let target = select_diff(ui, &tx, &target_commit, &matcher, &diff_selector)?;
223223

224+
let legacy_change_id_behavior = tx.settings().get_bool("split.legacy-change-id-behavior")?;
225+
224226
// Create the first commit, which includes the changes selected by the user.
225227
let mut first_commit = {
226228
let mut commit_builder = tx.repo_mut().rewrite_commit(&target.commit).detach();
227229
commit_builder.set_tree_id(target.selected_tree.id());
230+
if !legacy_change_id_behavior {
231+
// Generate a new change id so that the commit being split doesn't
232+
// become divergent.
233+
commit_builder.generate_new_change_id();
234+
}
228235
let description = if !args.message_paragraphs.is_empty() {
229236
let description = join_message_paragraphs(&args.message_paragraphs);
230237
if !description.is_empty() {
@@ -269,10 +276,12 @@ pub(crate) fn cmd_split(
269276
let mut commit_builder = tx.repo_mut().rewrite_commit(&target.commit).detach();
270277
commit_builder
271278
.set_parents(parents)
272-
.set_tree_id(new_tree.id())
279+
.set_tree_id(new_tree.id());
280+
if legacy_change_id_behavior {
273281
// Generate a new change id so that the commit being split doesn't
274282
// become divergent.
275-
.generate_new_change_id();
283+
commit_builder.generate_new_change_id();
284+
}
276285
let description = if target.commit.description().is_empty() {
277286
// If there was no description before, don't ask for one for the
278287
// second commit.
@@ -300,6 +309,9 @@ pub(crate) fn cmd_split(
300309
if legacy_bookmark_behavior {
301310
tx.repo_mut()
302311
.set_rewritten_commit(target.commit.id().clone(), second_commit.id().clone());
312+
} else {
313+
tx.repo_mut()
314+
.set_rewritten_commit(target.commit.id().clone(), first_commit.id().clone());
303315
}
304316

305317
let mut rewritten_commits = HashMap::<CommitId, CommitId>::new();

cli/src/config-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@
785785
"legacy-bookmark-behavior": {
786786
"type": "boolean",
787787
"description": "If true, bookmarks will move to the second commit instead of the first.",
788+
"default": true
789+
},
790+
"legacy-change-id-behavior": {
791+
"type": "boolean",
792+
"description": "If true, the first commit will get the original change id instead of the second commit.",
788793
"default": false
789794
}
790795
}

cli/src/config/misc.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ auto-update-stale = false
5555
# in the future.
5656
[split]
5757
legacy-bookmark-behavior = true
58+
legacy-change-id-behavior = false

0 commit comments

Comments
 (0)