mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-25 05:29:39 +00:00
cli: fix jj squash on empty commit
Fixes #787 If `jj squash` is run on an empty commit, it fails with "Error: No changes selected" With this change such squash command will behave like `jj abandon`.
This commit is contained in:
parent
5421f5e92d
commit
e7077909c1
2 changed files with 27 additions and 1 deletions
|
@ -2136,7 +2136,7 @@ from the source will be moved into the parent.
|
|||
args.interactive,
|
||||
matcher.as_ref(),
|
||||
)?;
|
||||
if &new_parent_tree_id == parent.tree_id() {
|
||||
if args.interactive && &new_parent_tree_id == parent.tree_id() {
|
||||
return Err(user_error("No changes selected"));
|
||||
}
|
||||
// Abandon the child if the parent now has all the content from the child
|
||||
|
|
|
@ -311,6 +311,32 @@ fn test_squash_description() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_squash_empty() {
|
||||
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");
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "parent"]);
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Working copy now at: e45abe2cd9a9 (no description set)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
||||
parent
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "child"]);
|
||||
test_env.set_up_fake_editor();
|
||||
test_env.jj_cmd_success(&repo_path, &["squash"]);
|
||||
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
||||
parent
|
||||
|
||||
child
|
||||
"###);
|
||||
}
|
||||
|
||||
fn get_description(test_env: &TestEnvironment, repo_path: &Path, rev: &str) -> String {
|
||||
test_env.jj_cmd_success(
|
||||
repo_path,
|
||||
|
|
Loading…
Reference in a new issue