From 5fd28d490b2b5627f2bdb8e1318c70de4469eb13 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 12 Sep 2025 09:01:01 +0100 Subject: fix(sync): dont fetch tags available locally as it was only checking if tip is a commit thats present but a tip could be an annotated tag --- src/bin/ngit/sub_commands/init.rs | 9 ++++++++- src/bin/ngit/sub_commands/sync.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/bin/ngit/sub_commands') diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 11a812b..385eeca 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -9,6 +9,7 @@ use std::{ use anyhow::{Context, Result, bail}; use console::{Style, Term}; +use git2::Oid; use ngit::{ UrlWithoutSlash, cli_interactor::{ @@ -794,7 +795,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let mut required_oids = vec![]; for tip in origin_state.values() { if let Ok(exist) = git_repo.does_commit_exist(tip) { - if !exist { + let oid_exists_as_tag = Oid::from_str(tip).is_ok_and(|tip| { + git_repo + .git_repo + .find_object(tip, Some(git2::ObjectType::Tag)) + .is_ok() + }); + if !exist && !oid_exists_as_tag { required_oids.push(tip.clone()); } } diff --git a/src/bin/ngit/sub_commands/sync.rs b/src/bin/ngit/sub_commands/sync.rs index 1a2d4ee..0860cc4 100644 --- a/src/bin/ngit/sub_commands/sync.rs +++ b/src/bin/ngit/sub_commands/sync.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use anyhow::{Context, Result, bail}; use console::Term; +use git2::Oid; use ngit::{ client::{ Client, Connect, Params, fetching_with_report, get_repo_ref_from_cache, @@ -239,7 +240,14 @@ fn identify_missing_refs(git_repo: &Repo, state: &HashMap) -> Ve let mut missing_oids = vec![]; for tip in state.values() { if let Ok(exist) = git_repo.does_commit_exist(tip) { - if !exist { + let oid_exists_as_tag = Oid::from_str(tip).is_ok_and(|tip| { + git_repo + .git_repo + .find_object(tip, Some(git2::ObjectType::Tag)) + .is_ok() + }); + + if !exist && !oid_exists_as_tag { missing_oids.push(tip.to_string()); } } -- cgit v1.2.3