@@ -406,3 +406,62 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
406406 git_remote_free (remote );
407407 git_buf_free (& path );
408408}
409+
410+ static int nrefs_found ;
411+ static bool count_refs_called ;
412+
413+ int count_refs (const char * ref_name , const char * remote_url , const git_oid * oid , unsigned int is_merge , void * payload )
414+ {
415+ const char * pfix = (const char * ) payload ;
416+
417+ GIT_UNUSED (remote_url );
418+ GIT_UNUSED (oid );
419+ GIT_UNUSED (is_merge );
420+
421+ count_refs_called = true;
422+ if (!git__prefixcmp (ref_name , pfix ))
423+ nrefs_found ++ ;
424+
425+ return 0 ;
426+ }
427+
428+ void test_fetchhead_nonetwork__create_with_multiple_refspecs (void )
429+ {
430+ git_remote * remote ;
431+ git_buf path = GIT_BUF_INIT ;
432+
433+ cl_set_cleanup (& cleanup_repository , "./test1" );
434+ cl_git_pass (git_repository_init (& g_repo , "./test1" , 0 ));
435+
436+ cl_git_pass (git_remote_create (& remote , g_repo , "origin" , cl_fixture ("testrepo.git" )));
437+ git_remote_free (remote );
438+ cl_git_pass (git_remote_add_fetch (g_repo , "origin" , "+refs/notes/*:refs/origin/notes/*" ));
439+ /* Pick up the new refspec */
440+ cl_git_pass (git_remote_lookup (& remote , g_repo , "origin" ));
441+
442+ cl_git_pass (git_buf_joinpath (& path , git_repository_path (g_repo ), "FETCH_HEAD" ));
443+ cl_assert (!git_path_exists (path .ptr ));
444+ cl_git_pass (git_remote_fetch (remote , NULL , NULL , NULL ));
445+ cl_assert (git_path_exists (path .ptr ));
446+
447+ count_refs_called = 0 ;
448+ nrefs_found = 0 ;
449+ cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/notes/" ));
450+ cl_assert (count_refs_called );
451+ cl_assert_equal_i (1 , nrefs_found );
452+
453+ count_refs_called = 0 ;
454+ nrefs_found = 0 ;
455+ cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/heads/" ));
456+ cl_assert (count_refs_called );
457+ cl_assert_equal_i (12 , nrefs_found );
458+
459+ count_refs_called = 0 ;
460+ nrefs_found = 0 ;
461+ cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/tags/" ));
462+ cl_assert (count_refs_called );
463+ cl_assert_equal_i (7 , nrefs_found );
464+
465+ git_remote_free (remote );
466+ git_buf_free (& path );
467+ }
0 commit comments