From 74c3d6f21cf2c0cec3ecfc7c3edcb4e50531d73d Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 28 Nov 2021 16:54:37 +0100 Subject: [PATCH] fetch all branches fetches tags aswell --- asyncgit/src/sync/remotes/mod.rs | 1 + asyncgit/src/sync/remotes/tags.rs | 42 +++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/asyncgit/src/sync/remotes/mod.rs b/asyncgit/src/sync/remotes/mod.rs index fb97e97c..aae4b2a1 100644 --- a/asyncgit/src/sync/remotes/mod.rs +++ b/asyncgit/src/sync/remotes/mod.rs @@ -90,6 +90,7 @@ fn fetch_from_remote( let mut options = FetchOptions::new(); let callbacks = Callbacks::new(progress_sender, basic_credential); options.prune(git2::FetchPrune::On); + options.download_tags(git2::AutotagOption::All); options.remote_callbacks(callbacks.callbacks()); remote.fetch(&[] as &[&str], Some(&mut options), None)?; diff --git a/asyncgit/src/sync/remotes/tags.rs b/asyncgit/src/sync/remotes/tags.rs index b019db96..6cae198e 100644 --- a/asyncgit/src/sync/remotes/tags.rs +++ b/asyncgit/src/sync/remotes/tags.rs @@ -152,7 +152,7 @@ mod tests { use super::*; use crate::sync::{ self, - remotes::{fetch, push::push}, + remotes::{fetch, fetch_all, push::push}, tests::{repo_clone, repo_init_bare}, }; use pretty_assertions::assert_eq; @@ -276,7 +276,7 @@ mod tests { } #[test] - fn test_tags_fetch_same_branch() { + fn test_tags_fetch() { let (r1_dir, _repo) = repo_init_bare().unwrap(); let r1_dir = r1_dir.path().to_str().unwrap(); @@ -312,4 +312,42 @@ mod tests { assert_eq!(tags1, tags2); } + + #[test] + fn test_tags_fetch_all() { + let (r1_dir, _repo) = repo_init_bare().unwrap(); + let r1_dir = r1_dir.path().to_str().unwrap(); + + let (clone1_dir, clone1) = repo_clone(r1_dir).unwrap(); + let clone1_dir = clone1_dir.path().to_str().unwrap(); + + let commit1 = + write_commit_file(&clone1, "test.txt", "test", "commit1"); + push( + clone1_dir, "origin", "master", false, false, None, None, + ) + .unwrap(); + + let (clone2_dir, _clone2) = repo_clone(r1_dir).unwrap(); + let clone2_dir = clone2_dir.path().to_str().unwrap(); + + // clone1 - creates tag + + sync::tag(clone1_dir, &commit1, "tag1").unwrap(); + + let tags1 = sync::get_tags(clone1_dir).unwrap(); + + push_tags(clone1_dir, "origin", None, None).unwrap(); + let tags_missing = + tags_missing_remote(clone1_dir, "origin", None).unwrap(); + assert!(tags_missing.is_empty()); + + // clone 2 - pull + + fetch_all(clone2_dir, &None, &None).unwrap(); + + let tags2 = sync::get_tags(clone2_dir).unwrap(); + + assert_eq!(tags1, tags2); + } }