mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-31 16:33:10 +00:00
cli: show commit summary at end of "branch create"
For the same reason as cdc0cc3601
. This will help notice problems like wrong
target revision.
The warning for multiple branches is reorganized as a hint for "-r" option,
which I think is the main purpose of this warning. Unlike "squash", we don't
check if an argument can be parsed as a revset because branch name is usually
a valid symbol expression.
This commit is contained in:
parent
e02c576282
commit
a5095c1da6
4 changed files with 34 additions and 12 deletions
|
@ -61,19 +61,25 @@ pub fn cmd_branch_create(
|
|||
}
|
||||
}
|
||||
|
||||
if branch_names.len() > 1 {
|
||||
writeln!(
|
||||
ui.warning_default(),
|
||||
"Creating multiple branches: {}",
|
||||
branch_names.join(", "),
|
||||
)?;
|
||||
}
|
||||
|
||||
let mut tx = workspace_command.start_transaction();
|
||||
for branch_name in branch_names {
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target(branch_name, RefTarget::normal(target_commit.id().clone()));
|
||||
}
|
||||
|
||||
if let Some(mut formatter) = ui.status_formatter() {
|
||||
write!(
|
||||
formatter,
|
||||
"Created {} branches pointing to ",
|
||||
branch_names.len()
|
||||
)?;
|
||||
tx.write_commit_summary(formatter.as_mut(), &target_commit)?;
|
||||
writeln!(formatter)?;
|
||||
}
|
||||
if branch_names.len() > 1 && args.revision.is_none() {
|
||||
writeln!(ui.hint_default(), "Use -r to specify the target revision.")?;
|
||||
}
|
||||
|
||||
tx.finish(
|
||||
ui,
|
||||
format!(
|
||||
|
|
|
@ -25,7 +25,8 @@ fn test_branch_multiple_names() {
|
|||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo", "bar"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Warning: Creating multiple branches: foo, bar
|
||||
Created 2 branches pointing to qpvuntsm 230dd059 bar foo | (empty) (no description set)
|
||||
Hint: Use -r to specify the target revision.
|
||||
"###);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ bar foo 230dd059e1b0
|
||||
|
@ -55,6 +56,13 @@ fn test_branch_multiple_names() {
|
|||
◉ 230dd059e1b0
|
||||
◉ 000000000000
|
||||
"###);
|
||||
|
||||
// Hint should be omitted if -r is specified
|
||||
let (_stdout, stderr) =
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "-r@-", "foo", "bar"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 2 branches pointing to qpvuntsm 230dd059 bar foo | (empty) (no description set)
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -66,7 +74,9 @@ fn test_branch_at_root() {
|
|||
let (stdout, stderr) =
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "fred", "-r=root()"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 1 branches pointing to zzzzzzzz 00000000 fred | (empty) (no description set)
|
||||
"###);
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
|
@ -191,7 +201,9 @@ fn test_branch_move() {
|
|||
test_env.jj_cmd_ok(&repo_path, &["branch", "untrack", "foo@origin"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "delete", "foo"]);
|
||||
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 1 branches pointing to mzvwutvl 66d48752 foo | (empty) (no description set)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
||||
foo: mzvwutvl 66d48752 (empty) (no description set)
|
||||
foo@origin: qpvuntsm 1eb845f3 (empty) commit
|
||||
|
|
|
@ -400,6 +400,7 @@ fn test_git_colocated_branch_at_root() {
|
|||
let (_stdout, stderr) =
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo", "-r=root()"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 1 branches pointing to zzzzzzzz 00000000 foo | (empty) (no description set)
|
||||
Warning: Failed to export some branches:
|
||||
foo: Ref cannot point to the root commit in Git
|
||||
"###);
|
||||
|
@ -431,6 +432,7 @@ fn test_git_colocated_conflicting_git_refs() {
|
|||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, {
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 1 branches pointing to qpvuntsm 230dd059 main main/sub | (empty) (no description set)
|
||||
Warning: Failed to export some branches:
|
||||
main/sub: Failed to set: ...
|
||||
Hint: Git doesn't allow a branch name that looks like a parent directory of
|
||||
|
|
|
@ -521,7 +521,9 @@ fn test_all_modifier() {
|
|||
|
||||
// Command that accepts only single revision
|
||||
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "-rall:@", "x"]);
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Created 1 branches pointing to qpvuntsm 230dd059 x | (empty) (no description set)
|
||||
"###);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "set", "-rall:all()", "x"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Revset "all:all()" resolved to more than one revision
|
||||
|
|
Loading…
Reference in a new issue