From 5bd2ab76f4218b834f92e1c186fb8a08ad604bc0 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 2 Oct 2023 01:07:32 +0900 Subject: [PATCH] git: check reserved remote name while diffing As I'm going to add separate lists of changed git_refs/remote_refs, it'll become a bit unclear which one we should check for reserved remotes. The diff might also be reorganized as a list of (remote, name, kind, old_target, new_target) where remote == "git" means the git-tracking branch. In this data structure, the notion of reserved remote name would be lost. --- lib/src/git.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index 8b89e0cae..7eecf14a6 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -193,9 +193,6 @@ pub fn import_some_refs( old_git_head.is_present().then(RefTarget::absent) }; let changed_remote_refs = diff_refs_to_import(mut_repo.view(), git_repo, git_ref_filter)?; - if changed_remote_refs.keys().any(is_reserved_git_remote_ref) { - return Err(GitImportError::RemoteReservedForLocalGitRepo); - } // Import new heads let store = mut_repo.store(); @@ -341,6 +338,9 @@ fn diff_refs_to_import( if !git_ref_filter(&ref_name) { continue; } + if is_reserved_git_remote_ref(&ref_name) { + return Err(GitImportError::RemoteReservedForLocalGitRepo); + } let old_target = known_remote_refs.get(&ref_name).copied().flatten(); let Some(id) = resolve_git_ref_to_commit_id(&git_ref, old_target) else { // Skip (or remove existing) invalid refs.