mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 07:14:38 +00:00
cli: teach jj split
to include all specified paths in first commit
This commit is contained in:
parent
d6d2b8b5bc
commit
109a9422f0
3 changed files with 72 additions and 1 deletions
|
@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
mode). For example, use `jj move --to @-- foo` to move the changes to file
|
mode). For example, use `jj move --to @-- foo` to move the changes to file
|
||||||
(or directory) `foo` in the working copy to the grandparent commit.
|
(or directory) `foo` in the working copy to the grandparent commit.
|
||||||
|
|
||||||
|
* `jj split` now lets you specify on the CLI which paths to include in the first
|
||||||
|
commit. The interactive diff-editing is not started when you do that.
|
||||||
|
|
||||||
* The `$JJ_CONFIG` environment variable can now point to a directory. If it
|
* The `$JJ_CONFIG` environment variable can now point to a directory. If it
|
||||||
does, all files in the directory will be read, in alphabetical order.
|
does, all files in the directory will be read, in alphabetical order.
|
||||||
|
|
||||||
|
|
|
@ -1366,6 +1366,8 @@ struct SplitArgs {
|
||||||
/// The revision to split
|
/// The revision to split
|
||||||
#[clap(long, short, default_value = "@")]
|
#[clap(long, short, default_value = "@")]
|
||||||
revision: String,
|
revision: String,
|
||||||
|
/// Put these paths in the first commit and don't run the diff editor
|
||||||
|
paths: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge work from multiple branches
|
/// Merge work from multiple branches
|
||||||
|
@ -3497,7 +3499,14 @@ any changes, then the operation will be aborted.
|
||||||
",
|
",
|
||||||
short_commit_description(&commit)
|
short_commit_description(&commit)
|
||||||
);
|
);
|
||||||
let tree_id = workspace_command.edit_diff(&base_tree, &commit.tree(), &instructions)?;
|
let tree_id = workspace_command.select_diff(
|
||||||
|
ui,
|
||||||
|
&base_tree,
|
||||||
|
&commit.tree(),
|
||||||
|
&instructions,
|
||||||
|
args.paths.is_empty(),
|
||||||
|
&args.paths,
|
||||||
|
)?;
|
||||||
if &tree_id == commit.tree().id() {
|
if &tree_id == commit.tree().id() {
|
||||||
ui.write("Nothing changed.\n")?;
|
ui.write("Nothing changed.\n")?;
|
||||||
} else {
|
} else {
|
||||||
|
|
59
tests/test_split_command.rs
Normal file
59
tests/test_split_command.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2022 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use crate::common::TestEnvironment;
|
||||||
|
|
||||||
|
pub mod common;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_split() {
|
||||||
|
let mut test_env = TestEnvironment::default();
|
||||||
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
|
||||||
|
std::fs::write(repo_path.join("file1"), "foo").unwrap();
|
||||||
|
std::fs::write(repo_path.join("file2"), "foo").unwrap();
|
||||||
|
std::fs::write(repo_path.join("file3"), "foo").unwrap();
|
||||||
|
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.short()"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ 9d08ea8cac40
|
||||||
|
o 000000000000
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let edit_script = test_env.set_up_fake_editor();
|
||||||
|
std::fs::write(edit_script, "").unwrap();
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
First part: 5eebce1de3b0
|
||||||
|
Second part: 45833353d94e
|
||||||
|
Working copy now at: 45833353d94e
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.short()"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ 45833353d94e
|
||||||
|
o 5eebce1de3b0
|
||||||
|
o 000000000000
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
|
||||||
|
insta::assert_snapshot!(stdout, @"A file2
|
||||||
|
");
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
A file1
|
||||||
|
A file3
|
||||||
|
"###);
|
||||||
|
}
|
Loading…
Reference in a new issue