From eedc315821a972e373bfa51d11114ef94b0081db Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 21 May 2022 06:38:56 -0700 Subject: [PATCH] cli: make `jj new` always check out the new commit Before this change, `jj new` would check out the new commit only if it was created on top of the current commit. I never liked that special-casing, and after thinking more about how the open/closed should work (see discussion #321), I think we want `jj new` to behave similar to how `git/hg checkout` works, so it can effectively replace the current `jj checkout` command for the use case of starting new work on top of an existing commit. --- CHANGELOG.md | 3 +++ src/commands.rs | 9 ++------- tests/test_new.rs | 12 +++++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2870c5c8..1cc57ef2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Use `jj log -r 'all()'` for the old behavior. Read more about revsets [here](https://github.com/martinvonz/jj/blob/main/docs/revsets.md). +* `jj new` now always checks out the new commit (used to be only if the parent + was `@`). + ### New features * `jj rebase` now accepts a `--branch/-b ` argument, which can be used diff --git a/src/commands.rs b/src/commands.rs index a2d487723..623c9bf5f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1382,7 +1382,7 @@ struct AbandonArgs { revisions: String, } -/// Create a new, empty change +/// Create a new, empty change and check it out /// /// This may be useful if you want to make some changes you're unsure of on top /// of the working copy. If the changes turned out to be useful, you can `jj @@ -1391,9 +1391,6 @@ struct AbandonArgs { #[derive(clap::Args, Clone, Debug)] struct NewArgs { /// Parent of the new change - /// - /// If the parent is the working copy, then the new change will be checked - /// out. #[clap(default_value = "@")] revision: String, /// The change description to use @@ -3371,9 +3368,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C let mut_repo = tx.mut_repo(); let new_commit = commit_builder.write_to_repo(mut_repo); let workspace_id = workspace_command.workspace_id(); - if mut_repo.view().get_checkout(&workspace_id) == Some(parent.id()) { - mut_repo.check_out(workspace_id, ui.settings(), &new_commit); - } + mut_repo.check_out(workspace_id, ui.settings(), &new_commit); workspace_command.finish_transaction(ui, tx)?; Ok(()) } diff --git a/tests/test_new.rs b/tests/test_new.rs index 866a2420a..447907c4c 100644 --- a/tests/test_new.rs +++ b/tests/test_new.rs @@ -17,7 +17,7 @@ use crate::common::TestEnvironment; pub mod common; #[test] -fn test_new_with_message() { +fn test_new() { let 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"); @@ -31,4 +31,14 @@ fn test_new_with_message() { o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file o 0000000000000000000000000000000000000000 (no description set) "###); + + // Start a new change off of a specific commit (the root commit in this case). + test_env.jj_cmd_success(&repo_path, &["new", "-m", "off of root", "root"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id \" \" description"]); + insta::assert_snapshot!(stdout, @r###" + @ d8c0a3e1570f1f5b08113a3427b3160900c3d48e off of root + | o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file + |/ + o 0000000000000000000000000000000000000000 (no description set) + "###); }