mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 21:27:06 +00:00
cli: inline branch_updates_for_push()
There are only two callers, and one of them knows that the branch exists.
This commit is contained in:
parent
d564c94548
commit
78e8790e10
1 changed files with 17 additions and 25 deletions
|
@ -694,14 +694,17 @@ fn cmd_git_push(
|
||||||
if !seen_branches.insert(branch_name.clone()) {
|
if !seen_branches.insert(branch_name.clone()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(update) = branch_updates_for_push(repo.as_ref(), &remote, branch_name)? {
|
let branch_target = repo
|
||||||
branch_updates.push((branch_name.clone(), update));
|
.view()
|
||||||
} else {
|
.get_branch(branch_name)
|
||||||
writeln!(
|
.ok_or_else(|| user_error(format!("Branch {branch_name} doesn't exist")))?;
|
||||||
|
match classify_branch_update(branch_name, branch_target, &remote) {
|
||||||
|
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
|
||||||
|
Ok(None) => writeln!(
|
||||||
ui,
|
ui,
|
||||||
"Branch {}@{} already matches {}",
|
"Branch {branch_name}@{remote} already matches {branch_name}",
|
||||||
branch_name, &remote, branch_name
|
)?,
|
||||||
)?;
|
Err(message) => return Err(user_error(message)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,14 +745,14 @@ fn cmd_git_push(
|
||||||
}
|
}
|
||||||
tx.mut_repo()
|
tx.mut_repo()
|
||||||
.set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone()));
|
.set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone()));
|
||||||
if let Some(update) = branch_updates_for_push(tx.mut_repo(), &remote, &branch_name)? {
|
let branch_target = tx.repo().view().get_branch(&branch_name).unwrap();
|
||||||
branch_updates.push((branch_name.clone(), update));
|
match classify_branch_update(&branch_name, branch_target, &remote) {
|
||||||
} else {
|
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
|
||||||
writeln!(
|
Ok(None) => writeln!(
|
||||||
ui,
|
ui,
|
||||||
"Branch {}@{} already matches {}",
|
"Branch {branch_name}@{remote} already matches {branch_name}",
|
||||||
branch_name, &remote, branch_name
|
)?,
|
||||||
)?;
|
Err(message) => return Err(user_error(message)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -969,17 +972,6 @@ fn get_default_push_remote(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn branch_updates_for_push(
|
|
||||||
repo: &dyn Repo,
|
|
||||||
remote_name: &str,
|
|
||||||
branch_name: &str,
|
|
||||||
) -> Result<Option<BranchPushUpdate>, CommandError> {
|
|
||||||
let maybe_branch_target = repo.view().get_branch(branch_name);
|
|
||||||
let branch_target = maybe_branch_target
|
|
||||||
.ok_or_else(|| user_error(format!("Branch {branch_name} doesn't exist")))?;
|
|
||||||
classify_branch_update(branch_name, branch_target, remote_name).map_err(user_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn classify_branch_update(
|
fn classify_branch_update(
|
||||||
branch_name: &str,
|
branch_name: &str,
|
||||||
branch_target: &BranchTarget,
|
branch_target: &BranchTarget,
|
||||||
|
|
Loading…
Reference in a new issue