]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
279afd2a CMN |
2 | #include "buffer.h" |
3 | #include "refspec.h" | |
7a544966 | 4 | #include "transport.h" |
3a2626f3 | 5 | |
9462c471 VM |
6 | static git_remote *_remote; |
7 | static git_repository *_repo; | |
8 | static const git_refspec *_refspec; | |
3a2626f3 CMN |
9 | |
10 | void test_network_remotes__initialize(void) | |
11 | { | |
9462c471 VM |
12 | cl_fixture_sandbox("testrepo.git"); |
13 | ||
14 | cl_git_pass(git_repository_open(&_repo, "testrepo.git")); | |
15 | cl_git_pass(git_remote_load(&_remote, _repo, "test")); | |
16 | ||
17 | _refspec = git_remote_fetchspec(_remote); | |
18 | cl_assert(_refspec != NULL); | |
3a2626f3 CMN |
19 | } |
20 | ||
21 | void test_network_remotes__cleanup(void) | |
22 | { | |
9462c471 VM |
23 | git_remote_free(_remote); |
24 | git_repository_free(_repo); | |
25 | cl_fixture_cleanup("testrepo.git"); | |
3a2626f3 CMN |
26 | } |
27 | ||
28 | void test_network_remotes__parsing(void) | |
29 | { | |
946a6dc4 VM |
30 | cl_assert_equal_s(git_remote_name(_remote), "test"); |
31 | cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2"); | |
3a2626f3 CMN |
32 | } |
33 | ||
58448910 RW |
34 | void test_network_remotes__parsing_ssh_remote(void) |
35 | { | |
36 | cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") ); | |
37 | } | |
38 | ||
7a544966 | 39 | void test_network_remotes__parsing_local_path_fails_if_path_not_found(void) |
58448910 RW |
40 | { |
41 | cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") ); | |
42 | } | |
43 | ||
7a544966 RW |
44 | void test_network_remotes__supported_transport_methods_are_supported(void) |
45 | { | |
46 | cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") ); | |
47 | } | |
48 | ||
49 | void test_network_remotes__unsupported_transport_methods_are_unsupported(void) | |
50 | { | |
51 | cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") ); | |
52 | } | |
53 | ||
3a2626f3 CMN |
54 | void test_network_remotes__refspec_parsing(void) |
55 | { | |
946a6dc4 VM |
56 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
57 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*"); | |
3a2626f3 CMN |
58 | } |
59 | ||
bcb8c007 CMN |
60 | void test_network_remotes__set_fetchspec(void) |
61 | { | |
62 | cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*")); | |
63 | _refspec = git_remote_fetchspec(_remote); | |
946a6dc4 VM |
64 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/*"); |
65 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); | |
bcb8c007 CMN |
66 | } |
67 | ||
68 | void test_network_remotes__set_pushspec(void) | |
69 | { | |
70 | cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*")); | |
71 | _refspec = git_remote_pushspec(_remote); | |
946a6dc4 VM |
72 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/*"); |
73 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); | |
bcb8c007 CMN |
74 | } |
75 | ||
89e5ed98 CMN |
76 | void test_network_remotes__save(void) |
77 | { | |
78 | git_remote_free(_remote); | |
79 | ||
80 | /* Set up the remote and save it to config */ | |
81 | cl_git_pass(git_remote_new(&_remote, _repo, "git://github.com/libgit2/libgit2", "upstream")); | |
82 | cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*")); | |
83 | cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*")); | |
84 | cl_git_pass(git_remote_save(_remote)); | |
85 | git_remote_free(_remote); | |
86 | _remote = NULL; | |
87 | ||
88 | /* Load it from config and make sure everything matches */ | |
89 | cl_git_pass(git_remote_load(&_remote, _repo, "upstream")); | |
90 | ||
91 | _refspec = git_remote_fetchspec(_remote); | |
92 | cl_assert(_refspec != NULL); | |
946a6dc4 VM |
93 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
94 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*"); | |
89e5ed98 CMN |
95 | |
96 | _refspec = git_remote_pushspec(_remote); | |
97 | cl_assert(_refspec != NULL); | |
946a6dc4 VM |
98 | cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); |
99 | cl_assert_equal_s(git_refspec_dst(_refspec), "refs/heads/*"); | |
89e5ed98 CMN |
100 | } |
101 | ||
3a2626f3 CMN |
102 | void test_network_remotes__fnmatch(void) |
103 | { | |
9462c471 VM |
104 | cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/master")); |
105 | cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/multi/level/branch")); | |
3a2626f3 CMN |
106 | } |
107 | ||
108 | void test_network_remotes__transform(void) | |
109 | { | |
110 | char ref[1024]; | |
111 | ||
112 | memset(ref, 0x0, sizeof(ref)); | |
9462c471 | 113 | cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master")); |
946a6dc4 | 114 | cl_assert_equal_s(ref, "refs/remotes/test/master"); |
3a2626f3 | 115 | } |
279afd2a CMN |
116 | |
117 | void test_network_remotes__transform_r(void) | |
118 | { | |
119 | git_buf buf = GIT_BUF_INIT; | |
120 | ||
121 | cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master")); | |
946a6dc4 | 122 | cl_assert_equal_s(git_buf_cstr(&buf), "refs/remotes/test/master"); |
771cde43 | 123 | git_buf_free(&buf); |
279afd2a | 124 | } |
9554cd51 CMN |
125 | |
126 | void test_network_remotes__missing_refspecs(void) | |
127 | { | |
128 | git_config *cfg; | |
129 | ||
130 | git_remote_free(_remote); | |
131 | ||
132 | cl_git_pass(git_repository_config(&cfg, _repo)); | |
133 | cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); | |
134 | cl_git_pass(git_remote_load(&_remote, _repo, "specless")); | |
135 | ||
136 | git_config_free(cfg); | |
137 | } | |
8171998f CMN |
138 | |
139 | void test_network_remotes__list(void) | |
140 | { | |
141 | git_strarray list; | |
142 | git_config *cfg; | |
143 | ||
144 | cl_git_pass(git_remote_list(&list, _repo)); | |
145 | cl_assert(list.count == 1); | |
146 | git_strarray_free(&list); | |
147 | ||
148 | cl_git_pass(git_repository_config(&cfg, _repo)); | |
149 | cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); | |
150 | cl_git_pass(git_remote_list(&list, _repo)); | |
151 | cl_assert(list.count == 2); | |
152 | git_strarray_free(&list); | |
153 | ||
154 | git_config_free(cfg); | |
155 | } |