Skip to content

Commit

Permalink
cli: print hint about defining jj co alias to avoid warning
Browse files Browse the repository at this point in the history
It can take a while to get used to the slightly different mental model
of `jj new` if you're used to `git/hg checkout`. Let's help users
define an alias to avoid the warning `jj checkout` currently prints. I
think users will still slowly get used to running `jj new` instead of
`jj checkout`. I think this patch might just make that process slower
(bad) and less frustrating (good).
  • Loading branch information
martinvonz committed Mar 5, 2024
1 parent 1e22416 commit 9216016
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/src/commands/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ pub(crate) fn cmd_checkout(
ui.warning(),
"warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent"
)?;
let mut workspace_command = command.workspace_helper(ui)?;
writeln!(
ui.hint(),
r#"Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message."#
)?;
let mut workspace_command = command.workspace_helper(ui)?;
let target = workspace_command.resolve_single_rev(&args.revision)?;
let mut tx = workspace_command.start_transaction();
let commit_builder = tx
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/test_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn test_checkout() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent
Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message.
Working copy now at: zsuskuln 05ce7118 (empty) (no description set)
Parent commit : rlvkpnrz 5c52832c (empty) second
"###);
Expand Down Expand Up @@ -66,6 +67,7 @@ fn test_checkout_not_single_rev() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "root()..@"]);
insta::assert_snapshot!(stderr, @r###"
warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent
Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message.
Error: Revset "root()..@" resolved to more than one revision
Hint: The revset "root()..@" resolved to these revisions:
royxmykx 2f859371 (empty) (no description set)
Expand All @@ -79,6 +81,7 @@ fn test_checkout_not_single_rev() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "root()..@-"]);
insta::assert_snapshot!(stderr, @r###"
warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent
Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message.
Error: Revset "root()..@-" resolved to more than one revision
Hint: The revset "root()..@-" resolved to these revisions:
mzvwutvl 5c1afd8b (empty) fifth
Expand All @@ -91,6 +94,7 @@ fn test_checkout_not_single_rev() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "@-|@--"]);
insta::assert_snapshot!(stderr, @r###"
warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent
Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message.
Error: Revset "@-|@--" resolved to more than one revision
Hint: The revset "@-|@--" resolved to these revisions:
mzvwutvl 5c1afd8b (empty) fifth
Expand All @@ -100,6 +104,7 @@ fn test_checkout_not_single_rev() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "none()"]);
insta::assert_snapshot!(stderr, @r###"
warning: `jj checkout` is deprecated; use `jj new` instead, which is equivalent
Run e.g. `jj config set --user aliases.co '["new"]'` to disable this message.
Error: Revset "none()" didn't resolve to any revisions
"###);
}
Expand Down

0 comments on commit 9216016

Please sign in to comment.