ok/jj
1
0
Fork 0
forked from mirrors/jj

split: allow creation of empty parent or child

jj split .           => create an empty child
jj split nonexistent => create an empty parent
This commit is contained in:
Samuel Tardieu 2023-01-29 07:35:41 +01:00
parent 200f40b836
commit fc59db5d52
3 changed files with 59 additions and 2 deletions

View file

@ -89,6 +89,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Commands that draw an ASCII graph (`jj log`, `jj op log`, `jj obslog`) now * Commands that draw an ASCII graph (`jj log`, `jj op log`, `jj obslog`) now
have different styles available by setting e.g. `ui.graph.style = "curved"`. have different styles available by setting e.g. `ui.graph.style = "curved"`.
* `jj split` accepts creating empty commits when given a path. `jj split .`
inserts an empty commit between the target commit and its children if any,
and `jj split any-non-existent-path` inserts an empty commit between the
target commit and its parents.
### Fixed bugs ### Fixed bugs
* When sharing the working copy with a Git repo, we used to forget to export * When sharing the working copy with a Git repo, we used to forget to export

View file

@ -2557,6 +2557,7 @@ fn cmd_split(ui: &mut Ui, command: &CommandHelper, args: &SplitArgs) -> Result<(
let mut tx = let mut tx =
workspace_command.start_transaction(&format!("split commit {}", commit.id().hex())); workspace_command.start_transaction(&format!("split commit {}", commit.id().hex()));
let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &commit.parents()); let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &commit.parents());
let interactive = args.paths.is_empty();
let instructions = format!( let instructions = format!(
"\ "\
You are splitting a commit in two: {} You are splitting a commit in two: {}
@ -2574,10 +2575,10 @@ don't make any changes, then the operation will be aborted.
&base_tree, &base_tree,
&commit.tree(), &commit.tree(),
&instructions, &instructions,
args.paths.is_empty(), interactive,
matcher.as_ref(), matcher.as_ref(),
)?; )?;
if &tree_id == commit.tree_id() { if &tree_id == commit.tree_id() && interactive {
ui.write("Nothing changed.\n")?; ui.write("Nothing changed.\n")?;
} else { } else {
let middle_tree = tx let middle_tree = tx

View file

@ -80,4 +80,55 @@ fn test_split_by_paths() {
A file1 A file1
A file3 A file3
"###); "###);
// Insert an empty commit after @- with "split ."
test_env.set_up_fake_editor();
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "."]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
First part: 31425b568fcf (no description set)
Second part: af0963926ac3 (no description set)
Working copy now at: 28d4ec20efa9 (no description set)
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "-T", r#"change_id.short() " " empty"#]);
insta::assert_snapshot!(stdout, @r###"
@ ffdaa62087a2 false
o 19b790168e73 true
o 9a45c67d3e96 false
o 000000000000 true
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@--"]);
insta::assert_snapshot!(stdout, @r###"
A file2
"###);
// Remove newly created empty commit
test_env.jj_cmd_success(&repo_path, &["abandon", "@-"]);
// Insert an empty commit before @- with "split nonexistent"
test_env.set_up_fake_editor();
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "nonexistent"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
First part: 0647b2cbd0da (no description set)
Second part: d5d77af65446 (no description set)
Working copy now at: 86f228dc3a50 (no description set)
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "-T", r#"change_id.short() " " empty"#]);
insta::assert_snapshot!(stdout, @r###"
@ ffdaa62087a2 false
o fa9213bcf78e false
o 9a45c67d3e96 true
o 000000000000 true
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
A file2
"###);
} }