@@ -121,6 +121,51 @@ void test_network_remote_remotes__urlresolve_passthrough(void)
121121 git_buf_dispose (& url );
122122}
123123
124+ void test_network_remote_remotes__instance_url (void )
125+ {
126+ git_buf url = GIT_BUF_INIT ;
127+ const char * orig_url = "git://github.com/libgit2/libgit2" ;
128+
129+ cl_assert_equal_s (git_remote_name (_remote ), "test" );
130+ cl_assert_equal_s (git_remote_url (_remote ), orig_url );
131+
132+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_FETCH , NULL ));
133+ cl_assert_equal_s (url .ptr , orig_url );
134+ git_buf_clear (& url );
135+
136+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_PUSH , NULL ));
137+ cl_assert_equal_s (url .ptr , orig_url );
138+ git_buf_clear (& url );
139+
140+ /* Setting the instance url updates the fetch and push URLs */
141+ git_remote_set_instance_url (_remote , "https://github.com/new/remote/url" );
142+ cl_assert_equal_s (git_remote_url (_remote ), "https://github.com/new/remote/url" );
143+ cl_assert_equal_p (git_remote_pushurl (_remote ), NULL );
144+
145+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_FETCH , NULL ));
146+ cl_assert_equal_s (url .ptr , "https://github.com/new/remote/url" );
147+ git_buf_clear (& url );
148+
149+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_PUSH , NULL ));
150+ cl_assert_equal_s (url .ptr , "https://github.com/new/remote/url" );
151+ git_buf_clear (& url );
152+
153+ /* Setting the instance push url updates only the push URL */
154+ git_remote_set_instance_pushurl (_remote , "https://github.com/new/push/url" );
155+ cl_assert_equal_s (git_remote_url (_remote ), "https://github.com/new/remote/url" );
156+ cl_assert_equal_s (git_remote_pushurl (_remote ), "https://github.com/new/push/url" );
157+
158+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_FETCH , NULL ));
159+ cl_assert_equal_s (url .ptr , "https://github.com/new/remote/url" );
160+ git_buf_clear (& url );
161+
162+ cl_git_pass (git_remote__urlfordirection (& url , _remote , GIT_DIRECTION_PUSH , NULL ));
163+ cl_assert_equal_s (url .ptr , "https://github.com/new/push/url" );
164+ git_buf_clear (& url );
165+
166+ git_buf_dispose (& url );
167+ }
168+
124169void test_network_remote_remotes__pushurl (void )
125170{
126171 const char * name = git_remote_name (_remote );
0 commit comments