22
33static git_repository * _repo ;
44static git_config * _config ;
5- static char url [] = "http://github.com/libgit2/libgit2.git" ;
5+
6+ #define TEST_URL "http://github.com/libgit2/libgit2.git"
7+
8+ #define cl_git_assert_cannot_create_remote (expected , creation_expr ) \
9+ do { \
10+ git_remote *r = NULL; \
11+ int res = ((creation_expr)); \
12+ cl_git_fail_with(expected, res); \
13+ cl_assert_equal_p(r, NULL); \
14+ } while (0);
15+
616
717void test_remote_create__initialize (void )
818{
@@ -27,11 +37,68 @@ void test_remote_create__manual(void)
2737{
2838 git_remote * remote ;
2939 cl_git_pass (git_config_set_string (_config , "remote.origin.fetch" , "+refs/heads/*:refs/remotes/origin/*" ));
30- cl_git_pass (git_config_set_string (_config , "remote.origin.url" , url ));
40+ cl_git_pass (git_config_set_string (_config , "remote.origin.url" , TEST_URL ));
3141
3242 cl_git_pass (git_remote_lookup (& remote , _repo , "origin" ));
3343 cl_assert_equal_s (git_remote_name (remote ), "origin" );
34- cl_assert_equal_s (git_remote_url (remote ), url );
44+ cl_assert_equal_s (git_remote_url (remote ), TEST_URL );
45+
46+ git_remote_free (remote );
47+ }
48+
49+ void test_remote_create__named (void )
50+ {
51+ git_remote * remote ;
52+ git_config * cfg ;
53+ const char * cfg_val ;
54+ cl_git_pass (git_remote_create (& remote , _repo , "valid-name" , TEST_URL ));
55+
56+ cl_assert_equal_s (git_remote_name (remote ), "valid-name" );
57+ cl_assert_equal_s (git_remote_url (remote ), TEST_URL );
58+
59+ cl_git_pass (git_repository_config_snapshot (& cfg , _repo ));
60+
61+ cl_git_pass (git_config_get_string (& cfg_val , cfg , "remote.valid-name.fetch" ));
62+ cl_assert_equal_s (cfg_val , "+refs/heads/*:refs/remotes/valid-name/*" );
63+
64+ cl_git_pass (git_config_get_string (& cfg_val , cfg , "remote.valid-name.url" ));
65+ cl_assert_equal_s (cfg_val , TEST_URL );
66+
67+ git_config_free (cfg );
68+ git_remote_free (remote );
69+ }
70+
71+ void test_remote_create__named_fail_on_invalid_name (void )
72+ {
73+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , NULL , TEST_URL ));
74+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , "Inv@{id" , TEST_URL ));
75+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , "" , TEST_URL ));
76+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , "/" , TEST_URL ));
77+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , "//" , TEST_URL ));
78+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , ".lock" , TEST_URL ));
79+ cl_git_assert_cannot_create_remote (GIT_EINVALIDSPEC , git_remote_create (& r , _repo , "a.lock" , TEST_URL ));
80+ }
81+
82+ void test_remote_create__named_fail_on_invalid_url (void )
83+ {
84+ cl_git_assert_cannot_create_remote (GIT_ERROR , git_remote_create (& r , _repo , "bad-url" , "" ));
85+ }
86+
87+ void test_remote_create__named_fail_on_conflicting_name (void )
88+ {
89+ cl_git_assert_cannot_create_remote (GIT_EEXISTS , git_remote_create (& r , _repo , "test" , TEST_URL ));
90+ }
91+
92+ void test_remote_create__with_fetchspec (void )
93+ {
94+ git_remote * remote ;
95+ git_strarray array ;
96+
97+ cl_git_pass (git_remote_create_with_fetchspec (& remote , _repo , "test-new" , "git://github.com/libgit2/libgit2" , "+refs/*:refs/*" ));
98+ cl_git_pass (git_remote_get_fetch_refspecs (& array , remote ));
99+ cl_assert_equal_s ("+refs/*:refs/*" , array .strings [0 ]);
100+ cl_assert_equal_i (1 , array .count );
35101
102+ git_strarray_free (& array );
36103 git_remote_free (remote );
37104}
0 commit comments