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

git: remove handling of real remote named "git", always override

#1690
This commit is contained in:
Yuya Nishihara 2023-08-22 15:53:29 +09:00
parent ce3d28e234
commit 55c6e90555
4 changed files with 19 additions and 50 deletions

View file

@ -322,19 +322,7 @@ fn cmd_branch_list(
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
let (mut all_branches, bad_branch_names) = git::build_unified_branches_map(repo.view());
if !bad_branch_names.is_empty() {
// TODO: This is not currently tested
writeln!(
ui.warning(),
"WARNING: Branch {branch_name} has a remote-tracking branch for a remote named `git`. \
Local-git tracking branches for it will not be shown.\nIt is recommended to rename \
that remote, as jj normally reserves the `@git` suffix to denote local-git tracking \
branches.",
branch_name = bad_branch_names.join(", "),
)?;
}
let mut all_branches = git::build_unified_branches_map(repo.view());
if !args.revisions.is_empty() {
// Match against local targets only, which is consistent with "jj git push".
fn local_targets(branch_target: &BranchTarget) -> impl Iterator<Item = &CommitId> {

View file

@ -355,7 +355,7 @@ impl RefNamesIndex {
fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex {
let mut index = RefNamesIndex::default();
let (all_branches, _) = git::build_unified_branches_map(repo.view());
let all_branches = git::build_unified_branches_map(repo.view());
for (branch_name, branch_target) in &all_branches {
let local_target = &branch_target.local_target;
let mut unsynced_remote_targets = branch_target

View file

@ -145,30 +145,18 @@ fn resolve_git_ref_to_commit_id(
}
/// Builds a map of branches which also includes pseudo `@git` remote.
///
/// If there's an existing remote named `git`, a list of conflicting branch
/// names will be returned.
pub fn build_unified_branches_map(view: &View) -> (BTreeMap<String, BranchTarget>, Vec<String>) {
pub fn build_unified_branches_map(view: &View) -> BTreeMap<String, BranchTarget> {
let mut all_branches = view.branches().clone();
let mut bad_branch_names = Vec::new();
for (branch_name, git_tracking_target) in local_branch_git_tracking_refs(view) {
// There may be a "git" remote if the view has been stored by older jj versions,
// but we override it anyway.
let branch_target = all_branches.entry(branch_name.to_owned()).or_default();
if branch_target
.remote_targets
.contains_key(REMOTE_NAME_FOR_LOCAL_GIT_REPO)
{
// TODO(#1690): There should be a mechanism to prevent importing a
// remote named "git" in `jj git import`.
bad_branch_names.push(branch_name.to_owned());
} else {
// TODO: `BTreeMap::try_insert` could be used here once that's stabilized.
branch_target.remote_targets.insert(
REMOTE_NAME_FOR_LOCAL_GIT_REPO.to_owned(),
git_tracking_target.clone(),
);
}
branch_target.remote_targets.insert(
REMOTE_NAME_FOR_LOCAL_GIT_REPO.to_owned(),
git_tracking_target.clone(),
);
}
(all_branches, bad_branch_names)
all_branches
}
fn local_branch_git_tracking_refs(view: &View) -> impl Iterator<Item = (&str, &RefTarget)> {

View file

@ -1885,26 +1885,19 @@ fn resolve_local_branch(repo: &dyn Repo, symbol: &str) -> Option<Vec<CommitId>>
fn resolve_remote_branch(repo: &dyn Repo, name: &str, remote: &str) -> Option<Vec<CommitId>> {
let view = repo.view();
let target = view.get_remote_branch(name, remote);
if target.is_present() {
return Some(target.added_ids().cloned().collect());
}
// A remote with name "git" will shadow local-git tracking branches
if remote == git::REMOTE_NAME_FOR_LOCAL_GIT_REPO {
let target = match name {
"HEAD" => view.git_head(),
_ => get_local_git_tracking_branch(view, name),
};
if target.is_present() {
return Some(target.added_ids().cloned().collect());
}
}
None
let target = match (name, remote) {
("HEAD", git::REMOTE_NAME_FOR_LOCAL_GIT_REPO) => view.git_head(),
(name, git::REMOTE_NAME_FOR_LOCAL_GIT_REPO) => get_local_git_tracking_branch(view, name),
(name, remote) => view.get_remote_branch(name, remote),
};
target
.is_present()
.then(|| target.added_ids().cloned().collect())
}
fn collect_branch_symbols(repo: &dyn Repo, include_synced_remotes: bool) -> Vec<String> {
let view = repo.view();
let (all_branches, _) = git::build_unified_branches_map(view);
let all_branches = git::build_unified_branches_map(view);
all_branches
.iter()
.flat_map(|(name, branch_target)| {