11#include "clar_libgit2.h"
22
3- static const char * refspec = "refs/heads/first-merge:refs/remotes/origin/first-merge" ;
3+ #define URL "git://github.com/libgit2/TestGitRepository"
4+ #define REFSPEC "refs/heads/first-merge:refs/remotes/origin/first-merge"
45
56static int remote_single_branch (git_remote * * out , git_repository * repo , const char * name , const char * url , void * payload )
67{
78 GIT_UNUSED (payload );
89
9- cl_git_pass (git_remote_create_with_fetchspec (out , repo , name , url , refspec ));
10+ cl_git_pass (git_remote_create_with_fetchspec (out , repo , name , url , REFSPEC ));
1011
1112 return 0 ;
1213}
@@ -22,7 +23,7 @@ void test_online_remotes__single_branch(void)
2223 opts .remote_cb = remote_single_branch ;
2324 opts .checkout_branch = "first-merge" ;
2425
25- cl_git_pass (git_clone (& repo , "git://github.com/libgit2/TestGitRepository" , "./single-branch" , & opts ));
26+ cl_git_pass (git_clone (& repo , URL , "./single-branch" , & opts ));
2627 cl_git_pass (git_reference_list (& refs , repo ));
2728
2829 for (i = 0 ; i < refs .count ; i ++ ) {
@@ -37,7 +38,7 @@ void test_online_remotes__single_branch(void)
3738 cl_git_pass (git_remote_get_fetch_refspecs (& refs , remote ));
3839
3940 cl_assert_equal_i (1 , refs .count );
40- cl_assert_equal_s (refspec , refs .strings [0 ]);
41+ cl_assert_equal_s (REFSPEC , refs .strings [0 ]);
4142
4243 git_strarray_free (& refs );
4344 git_remote_free (remote );
@@ -51,5 +52,76 @@ void test_online_remotes__restricted_refspecs(void)
5152
5253 opts .remote_cb = remote_single_branch ;
5354
54- cl_git_fail_with (GIT_EINVALIDSPEC , git_clone (& repo , "git://github.com/libgit2/TestGitRepository" , "./restrict-refspec" , & opts ));
55+ cl_git_fail_with (GIT_EINVALIDSPEC , git_clone (& repo , URL , "./restrict-refspec" , & opts ));
56+ }
57+
58+ void test_online_remotes__detached_remote_fails_downloading (void )
59+ {
60+ git_remote * remote ;
61+
62+ cl_git_pass (git_remote_create_detached (& remote , URL ));
63+ cl_git_pass (git_remote_connect (remote , GIT_DIRECTION_FETCH , NULL , NULL , NULL ));
64+ cl_git_fail (git_remote_download (remote , NULL , NULL ));
65+
66+ git_remote_free (remote );
67+ }
68+
69+ void test_online_remotes__detached_remote_fails_uploading (void )
70+ {
71+ git_remote * remote ;
72+
73+ cl_git_pass (git_remote_create_detached (& remote , URL ));
74+ cl_git_pass (git_remote_connect (remote , GIT_DIRECTION_FETCH , NULL , NULL , NULL ));
75+ cl_git_fail (git_remote_upload (remote , NULL , NULL ));
76+
77+ git_remote_free (remote );
78+ }
79+
80+ void test_online_remotes__detached_remote_fails_pushing (void )
81+ {
82+ git_remote * remote ;
83+
84+ cl_git_pass (git_remote_create_detached (& remote , URL ));
85+ cl_git_pass (git_remote_connect (remote , GIT_DIRECTION_FETCH , NULL , NULL , NULL ));
86+ cl_git_fail (git_remote_push (remote , NULL , NULL ));
87+
88+ git_remote_free (remote );
89+ }
90+
91+ void test_online_remotes__detached_remote_succeeds_ls (void )
92+ {
93+ const char * refs [] = {
94+ "HEAD" ,
95+ "refs/heads/first-merge" ,
96+ "refs/heads/master" ,
97+ "refs/heads/no-parent" ,
98+ "refs/tags/annotated_tag" ,
99+ "refs/tags/annotated_tag^{}" ,
100+ "refs/tags/blob" ,
101+ "refs/tags/commit_tree" ,
102+ "refs/tags/nearly-dangling" ,
103+ };
104+ const git_remote_head * * heads ;
105+ git_remote * remote ;
106+ size_t i , j , n ;
107+
108+ cl_git_pass (git_remote_create_detached (& remote , URL ));
109+ cl_git_pass (git_remote_connect (remote , GIT_DIRECTION_FETCH , NULL , NULL , NULL ));
110+ cl_git_pass (git_remote_ls (& heads , & n , remote ));
111+
112+ cl_assert_equal_sz (n , 9 );
113+ for (i = 0 ; i < n ; i ++ ) {
114+ char found = false;
115+
116+ for (j = 0 ; j < ARRAY_SIZE (refs ); j ++ ) {
117+ if (!strcmp (heads [i ]-> name , refs [j ])) {
118+ found = true;
119+ break ;
120+ }
121+ }
122+
123+ cl_assert_ (found , heads [i ]-> name );
124+ }
125+
126+ git_remote_free (remote );
55127}
0 commit comments