Skip to content

Commit 96bca11

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, and the change id
1 parent db2f15a commit 96bca11

File tree

4 files changed

+153
-198
lines changed

4 files changed

+153
-198
lines changed

cli/src/commands/split.rs

Lines changed: 11 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_bookmark_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_bookmark_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_bookmark_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.

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)