forked from mirrors/jj
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.
This commit is contained in:
parent
689d9a836a
commit
eedc315821
3 changed files with 16 additions and 8 deletions
|
@ -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
|
Use `jj log -r 'all()'` for the old behavior. Read more about revsets
|
||||||
[here](https://github.com/martinvonz/jj/blob/main/docs/revsets.md).
|
[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
|
### New features
|
||||||
|
|
||||||
* `jj rebase` now accepts a `--branch/-b <revision>` argument, which can be used
|
* `jj rebase` now accepts a `--branch/-b <revision>` argument, which can be used
|
||||||
|
|
|
@ -1382,7 +1382,7 @@ struct AbandonArgs {
|
||||||
revisions: String,
|
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
|
/// 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
|
/// 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)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
struct NewArgs {
|
struct NewArgs {
|
||||||
/// Parent of the new change
|
/// Parent of the new change
|
||||||
///
|
|
||||||
/// If the parent is the working copy, then the new change will be checked
|
|
||||||
/// out.
|
|
||||||
#[clap(default_value = "@")]
|
#[clap(default_value = "@")]
|
||||||
revision: String,
|
revision: String,
|
||||||
/// The change description to use
|
/// 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 mut_repo = tx.mut_repo();
|
||||||
let new_commit = commit_builder.write_to_repo(mut_repo);
|
let new_commit = commit_builder.write_to_repo(mut_repo);
|
||||||
let workspace_id = workspace_command.workspace_id();
|
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)?;
|
workspace_command.finish_transaction(ui, tx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::common::TestEnvironment;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_with_message() {
|
fn test_new() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
@ -31,4 +31,14 @@ fn test_new_with_message() {
|
||||||
o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
||||||
o 0000000000000000000000000000000000000000 (no description set)
|
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)
|
||||||
|
"###);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue