diff --git a/CHANGELOG.md b/CHANGELOG.md index 37bfed7bba..0b3b124b97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Templates now support the `>=`, `>`, `<=`, and `<` relational operators for `Integer` types. +* `jj split` now accepts `--second` to put specified paths into the second + commit instead of the first. + ### Fixed bugs * The `$NO_COLOR` environment variable must now be non-empty to be respected. diff --git a/cli/src/commands/split.rs b/cli/src/commands/split.rs index 25d2f01cf3..634d476e5d 100644 --- a/cli/src/commands/split.rs +++ b/cli/src/commands/split.rs @@ -15,6 +15,8 @@ use std::io::Write; use clap_complete::ArgValueCandidates; use clap_complete::ArgValueCompleter; +use jj_lib::matchers::DifferenceMatcher; +use jj_lib::matchers::EverythingMatcher; use jj_lib::object_id::ObjectId; use jj_lib::repo::Repo; use tracing::instrument; @@ -66,12 +68,16 @@ pub(crate) struct SplitArgs { // TODO: Delete `--siblings` alias in jj 0.25+ #[arg(long, short, alias = "siblings")] parallel: bool, - /// Put these paths in the first commit + /// Put these paths into one commit (the first by default). #[arg( value_hint = clap::ValueHint::AnyPath, add = ArgValueCompleter::new(complete::modified_revision_files), )] paths: Vec, + + /// Put the specified paths into the second commit instead of the first. + #[arg(long, short, conflicts_with_all = ["parallel", "interactive", "tool"])] + second: bool, } #[instrument(skip_all)] @@ -90,9 +96,13 @@ pub(crate) fn cmd_split( } workspace_command.check_rewritable([commit.id()])?; - let matcher = workspace_command + let mut matcher = workspace_command .parse_file_patterns(ui, &args.paths)? .to_matcher(); + if args.second { + matcher = Box::new(DifferenceMatcher::new(EverythingMatcher, matcher)); + } + let diff_selector = workspace_command.diff_selector( ui, args.tool.as_deref(), diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index d666a72bee..4f9fb095d6 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -2058,7 +2058,7 @@ Splitting an empty commit is not supported because the same effect can be achiev ###### **Arguments:** -* `` — Put these paths in the first commit +* `` — Put these paths into one commit (the first by default) ###### **Options:** @@ -2068,6 +2068,7 @@ Splitting an empty commit is not supported because the same effect can be achiev Default value: `@` * `-p`, `--parallel` — Split the revision into two parallel revisions instead of a parent and child +* `-s`, `--second` — Put the specified paths into the second commit instead of the first diff --git a/cli/tests/test_split_command.rs b/cli/tests/test_split_command.rs index ebe6891788..11fba68a84 100644 --- a/cli/tests/test_split_command.rs +++ b/cli/tests/test_split_command.rs @@ -150,6 +150,25 @@ fn test_split_by_paths() { insta::assert_snapshot!(stdout, @r###" A file2 "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@"]); + insta::assert_snapshot!(stdout, @r###" + A file1 + A file3 + "###); + + let (stdout, _) = test_env.jj_cmd_ok(&repo_path, &["split", "--second", "file3"]); + insta::assert_snapshot!(stdout, @""); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]); + insta::assert_snapshot!(stdout, @r###" + A file1 + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@"]); + insta::assert_snapshot!(stdout, @r###" + A file3 + "###); } #[test]