]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
279afd2a CMN |
2 | #include "buffer.h" |
3 | #include "refspec.h" | |
7a544966 | 4 | #include "transport.h" |
eff5b499 | 5 | #include "remote.h" |
3a2626f3 | 6 | |
9462c471 VM |
7 | static git_remote *_remote; |
8 | static git_repository *_repo; | |
9 | static const git_refspec *_refspec; | |
3a2626f3 CMN |
10 | |
11 | void test_network_remotes__initialize(void) | |
12 | { | |
9462c471 VM |
13 | cl_fixture_sandbox("testrepo.git"); |
14 | ||
15 | cl_git_pass(git_repository_open(&_repo, "testrepo.git")); | |
16 | cl_git_pass(git_remote_load(&_remote, _repo, "test")); | |
17 | ||
18 | _refspec = git_remote_fetchspec(_remote); | |
19 | cl_assert(_refspec != NULL); | |
3a2626f3 CMN |
20 | } |
21 | ||
22 | void test_network_remotes__cleanup(void) | |
23 | { | |
9462c471 VM |
24 | git_remote_free(_remote); |
25 | git_repository_free(_repo); | |
26 | cl_fixture_cleanup("testrepo.git"); | |
3a2626f3 CMN |
27 | } |
28 | ||
29 | void test_network_remotes__parsing(void) | |
30 | { | |
8689a69d SC |
31 | git_remote *_remote2 = NULL; |
32 | ||
946a6dc4 VM |
33 | cl_assert_equal_s(git_remote_name(_remote), "test"); |
34 | cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2"); | |
8689a69d SC |
35 | cl_assert(git_remote_pushurl(_remote) == NULL); |
36 | ||
eff5b499 SC |
37 | cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIR_FETCH), |
38 | "git://github.com/libgit2/libgit2"); | |
39 | cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIR_PUSH), | |
40 | "git://github.com/libgit2/libgit2"); | |
41 | ||
8689a69d SC |
42 | cl_git_pass(git_remote_load(&_remote2, _repo, "test_with_pushurl")); |
43 | cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl"); | |
44 | cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2"); | |
45 | cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2"); | |
eff5b499 SC |
46 | |
47 | cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIR_FETCH), | |
48 | "git://github.com/libgit2/fetchlibgit2"); | |
49 | cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIR_PUSH), | |
50 | "git://github.com/libgit2/pushlibgit2"); | |
51 | ||
8689a69d SC |
52 | git_remote_free(_remote2); |
53 | } | |
54 | ||
55 | void test_network_remotes__pushurl(void) | |
56 | { | |
57 | cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/notlibgit2")); | |
58 | cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2"); | |
59 | ||
60 | cl_git_pass(git_remote_set_pushurl(_remote, NULL)); | |
61 | cl_assert(git_remote_pushurl(_remote) == NULL); | |
3a2626f3 CMN |
62 | } |
63 | ||
58448910 RW |
64 | void test_network_remotes__parsing_ssh_remote(void) |
65 | { | |
66 | cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") ); | |
67 | } | |
68 | ||
7a544966 | 69 | void test_network_remotes__parsing_local_path_fails_if_path_not_found(void) |
58448910 RW |
70 | { |
71 | cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") ); | |
72 | } | |
73 | ||
7a544966 RW |
74 | void test_network_remotes__supported_transport_methods_are_supported(void) |
75 | { | |
76 | cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") ); | |
77 | } | |
78 | ||
79 | void test_network_remotes__unsupported_transport_methods_are_unsupported(void) | |
80 | { | |
81 | cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") ); | |
82 | } | |
83 | ||
3a2626f3 CMN |
84 | void test_network_remotes__refspec_parsing(void) |
85 | { | |
946a6dc4 VM |
86 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
87 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*"); | |
3a2626f3 CMN |
88 | } |
89 | ||
bcb8c007 CMN |
90 | void test_network_remotes__set_fetchspec(void) |
91 | { | |
92 | cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*")); | |
93 | _refspec = git_remote_fetchspec(_remote); | |
946a6dc4 VM |
94 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/*"); |
95 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); | |
bcb8c007 CMN |
96 | } |
97 | ||
98 | void test_network_remotes__set_pushspec(void) | |
99 | { | |
100 | cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*")); | |
101 | _refspec = git_remote_pushspec(_remote); | |
946a6dc4 VM |
102 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/*"); |
103 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); | |
bcb8c007 CMN |
104 | } |
105 | ||
89e5ed98 CMN |
106 | void test_network_remotes__save(void) |
107 | { | |
108 | git_remote_free(_remote); | |
109 | ||
110 | /* Set up the remote and save it to config */ | |
baaa8a44 | 111 | cl_git_pass(git_remote_new(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2", NULL)); |
89e5ed98 CMN |
112 | cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*")); |
113 | cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*")); | |
8689a69d | 114 | cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push")); |
89e5ed98 CMN |
115 | cl_git_pass(git_remote_save(_remote)); |
116 | git_remote_free(_remote); | |
117 | _remote = NULL; | |
118 | ||
119 | /* Load it from config and make sure everything matches */ | |
120 | cl_git_pass(git_remote_load(&_remote, _repo, "upstream")); | |
121 | ||
122 | _refspec = git_remote_fetchspec(_remote); | |
123 | cl_assert(_refspec != NULL); | |
946a6dc4 VM |
124 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
125 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*"); | |
d05e2c64 | 126 | cl_assert(git_refspec_force(_refspec) == 0); |
89e5ed98 CMN |
127 | |
128 | _refspec = git_remote_pushspec(_remote); | |
129 | cl_assert(_refspec != NULL); | |
946a6dc4 VM |
130 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
131 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/heads/*"); | |
8689a69d SC |
132 | |
133 | cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2"); | |
134 | cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/libgit2_push"); | |
413d5563 SC |
135 | |
136 | /* remove the pushurl again and see if we can save that too */ | |
137 | cl_git_pass(git_remote_set_pushurl(_remote, NULL)); | |
138 | cl_git_pass(git_remote_save(_remote)); | |
139 | git_remote_free(_remote); | |
140 | _remote = NULL; | |
141 | ||
142 | cl_git_pass(git_remote_load(&_remote, _repo, "upstream")); | |
143 | cl_assert(git_remote_pushurl(_remote) == NULL); | |
89e5ed98 CMN |
144 | } |
145 | ||
3a2626f3 CMN |
146 | void test_network_remotes__fnmatch(void) |
147 | { | |
3fbcac89 VM |
148 | cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master")); |
149 | cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch")); | |
3a2626f3 CMN |
150 | } |
151 | ||
152 | void test_network_remotes__transform(void) | |
153 | { | |
154 | char ref[1024]; | |
155 | ||
156 | memset(ref, 0x0, sizeof(ref)); | |
9462c471 | 157 | cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master")); |
946a6dc4 | 158 | cl_assert_equal_s(ref, "refs/remotes/test/master"); |
3a2626f3 | 159 | } |
279afd2a CMN |
160 | |
161 | void test_network_remotes__transform_r(void) | |
162 | { | |
163 | git_buf buf = GIT_BUF_INIT; | |
164 | ||
165 | cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master")); | |
946a6dc4 | 166 | cl_assert_equal_s(git_buf_cstr(&buf), "refs/remotes/test/master"); |
771cde43 | 167 | git_buf_free(&buf); |
279afd2a | 168 | } |
9554cd51 CMN |
169 | |
170 | void test_network_remotes__missing_refspecs(void) | |
171 | { | |
172 | git_config *cfg; | |
173 | ||
174 | git_remote_free(_remote); | |
175 | ||
176 | cl_git_pass(git_repository_config(&cfg, _repo)); | |
177 | cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); | |
178 | cl_git_pass(git_remote_load(&_remote, _repo, "specless")); | |
179 | ||
180 | git_config_free(cfg); | |
181 | } | |
8171998f CMN |
182 | |
183 | void test_network_remotes__list(void) | |
184 | { | |
185 | git_strarray list; | |
186 | git_config *cfg; | |
187 | ||
188 | cl_git_pass(git_remote_list(&list, _repo)); | |
e16fc07f | 189 | cl_assert(list.count == 3); |
8171998f CMN |
190 | git_strarray_free(&list); |
191 | ||
192 | cl_git_pass(git_repository_config(&cfg, _repo)); | |
193 | cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); | |
194 | cl_git_pass(git_remote_list(&list, _repo)); | |
e16fc07f | 195 | cl_assert(list.count == 4); |
8171998f CMN |
196 | git_strarray_free(&list); |
197 | ||
198 | git_config_free(cfg); | |
199 | } | |
9fb70f37 | 200 | |
201 | void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void) | |
202 | { | |
203 | cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago")); | |
204 | } | |
a209a025 | 205 | |
d27bf665 | 206 | /* |
207 | * $ git remote add addtest http://github.com/libgit2/libgit2 | |
208 | * | |
209 | * $ cat .git/config | |
210 | * [...] | |
211 | * [remote "addtest"] | |
212 | * url = http://github.com/libgit2/libgit2 | |
a146ba9e | 213 | * fetch = +refs/heads/\*:refs/remotes/addtest/\* |
d27bf665 | 214 | */ |
a209a025 CMN |
215 | void test_network_remotes__add(void) |
216 | { | |
217 | git_remote_free(_remote); | |
218 | cl_git_pass(git_remote_add(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2")); | |
219 | git_remote_free(_remote); | |
220 | ||
221 | cl_git_pass(git_remote_load(&_remote, _repo, "addtest")); | |
222 | _refspec = git_remote_fetchspec(_remote); | |
223 | cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*")); | |
d27bf665 | 224 | cl_assert(git_refspec_force(_refspec) == 1); |
a209a025 | 225 | cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*")); |
8689a69d | 226 | cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2"); |
a209a025 | 227 | } |