ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: branch: extract helper that checks if tracked remote branch exists

This commit is contained in:
Yuya Nishihara 2024-06-14 17:46:30 +09:00
parent 76ff35eba4
commit ce2e016e57
2 changed files with 9 additions and 8 deletions

View file

@ -159,6 +159,13 @@ fn find_remote_branches<'a>(
}
}
/// Whether or not the `branch` has any tracked remotes (i.e. is a tracking
/// local branch.)
fn has_tracked_remote_branches(view: &View, branch: &str) -> bool {
view.remote_branches_matching(&StringPattern::exact(branch), &StringPattern::everything())
.any(|(_, remote_ref)| remote_ref.is_tracking())
}
fn is_fast_forward(repo: &dyn Repo, old_target: &RefTarget, new_target_id: &CommitId) -> bool {
if old_target.is_present() {
// Strictly speaking, "all" old targets should be ancestors, but we allow

View file

@ -13,8 +13,8 @@
// limitations under the License.
use jj_lib::op_store::RefTarget;
use jj_lib::str_util::StringPattern;
use super::has_tracked_remote_branches;
use crate::cli_util::CommandHelper;
use crate::command_error::{user_error, CommandError};
use crate::ui::Ui;
@ -57,13 +57,7 @@ pub fn cmd_branch_rename(
tx.finish(ui, format!("rename branch {old_branch} to {new_branch}"))?;
let view = workspace_command.repo().view();
if view
.remote_branches_matching(
&StringPattern::exact(old_branch),
&StringPattern::everything(),
)
.any(|(_, remote_ref)| remote_ref.is_tracking())
{
if has_tracked_remote_branches(view, old_branch) {
writeln!(
ui.warning_default(),
"Branch {old_branch} has tracking remote branches which were not renamed."