forked from mirrors/jj
cli: reorder check of branch create/set arguments so they look similar
I think it's better to not emit "multiple branches" warning if we refuse to move branches.
This commit is contained in:
parent
e880976deb
commit
e2fd309d28
1 changed files with 17 additions and 19 deletions
|
@ -253,6 +253,8 @@ fn cmd_branch_create(
|
||||||
args: &BranchCreateArgs,
|
args: &BranchCreateArgs,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut workspace_command = command.workspace_helper(ui)?;
|
let mut workspace_command = command.workspace_helper(ui)?;
|
||||||
|
let target_commit =
|
||||||
|
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
|
||||||
let view = workspace_command.repo().view();
|
let view = workspace_command.repo().view();
|
||||||
let branch_names = &args.names;
|
let branch_names = &args.names;
|
||||||
if let Some(branch_name) = branch_names
|
if let Some(branch_name) = branch_names
|
||||||
|
@ -273,8 +275,6 @@ fn cmd_branch_create(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_commit =
|
|
||||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
|
|
||||||
let mut tx = workspace_command.start_transaction(&format!(
|
let mut tx = workspace_command.start_transaction(&format!(
|
||||||
"create {} pointing to commit {}",
|
"create {} pointing to commit {}",
|
||||||
make_branch_term(branch_names),
|
make_branch_term(branch_names),
|
||||||
|
@ -293,8 +293,22 @@ fn cmd_branch_set(
|
||||||
command: &CommandHelper,
|
command: &CommandHelper,
|
||||||
args: &BranchSetArgs,
|
args: &BranchSetArgs,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let branch_names = &args.names;
|
|
||||||
let mut workspace_command = command.workspace_helper(ui)?;
|
let mut workspace_command = command.workspace_helper(ui)?;
|
||||||
|
let target_commit =
|
||||||
|
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
|
||||||
|
let repo = workspace_command.repo().as_ref();
|
||||||
|
let branch_names = &args.names;
|
||||||
|
if !args.allow_backwards
|
||||||
|
&& !branch_names
|
||||||
|
.iter()
|
||||||
|
.all(|branch_name| is_fast_forward(repo, branch_name, target_commit.id()))
|
||||||
|
{
|
||||||
|
return Err(user_error_with_hint(
|
||||||
|
"Refusing to move branch backwards or sideways.",
|
||||||
|
"Use --allow-backwards to allow it.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if branch_names.len() > 1 {
|
if branch_names.len() > 1 {
|
||||||
writeln!(
|
writeln!(
|
||||||
ui.warning(),
|
ui.warning(),
|
||||||
|
@ -303,22 +317,6 @@ fn cmd_branch_set(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_commit =
|
|
||||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
|
|
||||||
if !args.allow_backwards
|
|
||||||
&& !branch_names.iter().all(|branch_name| {
|
|
||||||
is_fast_forward(
|
|
||||||
workspace_command.repo().as_ref(),
|
|
||||||
branch_name,
|
|
||||||
target_commit.id(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
{
|
|
||||||
return Err(user_error_with_hint(
|
|
||||||
"Refusing to move branch backwards or sideways.",
|
|
||||||
"Use --allow-backwards to allow it.",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
let mut tx = workspace_command.start_transaction(&format!(
|
let mut tx = workspace_command.start_transaction(&format!(
|
||||||
"point {} to commit {}",
|
"point {} to commit {}",
|
||||||
make_branch_term(branch_names),
|
make_branch_term(branch_names),
|
||||||
|
|
Loading…
Reference in a new issue