mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-07 17:27:40 +00:00
Remotes: Use correct url in git_remote_connect
This commit is contained in:
parent
413d556384
commit
eff5b49927
21
src/remote.c
21
src/remote.c
@ -356,13 +356,32 @@ const git_refspec *git_remote_pushspec(git_remote *remote)
|
|||||||
return &remote->push;
|
return &remote->push;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* git_remote__urlfordirection(git_remote *remote, int direction)
|
||||||
|
{
|
||||||
|
assert(remote);
|
||||||
|
|
||||||
|
if (direction == GIT_DIR_FETCH) {
|
||||||
|
return remote->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (direction == GIT_DIR_PUSH) {
|
||||||
|
return remote->pushurl ? remote->pushurl : remote->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int git_remote_connect(git_remote *remote, int direction)
|
int git_remote_connect(git_remote *remote, int direction)
|
||||||
{
|
{
|
||||||
git_transport *t;
|
git_transport *t;
|
||||||
|
|
||||||
assert(remote);
|
assert(remote);
|
||||||
|
|
||||||
if (git_transport_new(&t, remote->url) < 0)
|
const char* url = git_remote__urlfordirection(remote, direction);
|
||||||
|
if (url == NULL )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (git_transport_new(&t, url) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
t->check_cert = remote->check_cert;
|
t->check_cert = remote->check_cert;
|
||||||
|
@ -24,4 +24,6 @@ struct git_remote {
|
|||||||
check_cert;
|
check_cert;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char* git_remote__urlfordirection(struct git_remote *remote, int direction);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "refspec.h"
|
#include "refspec.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
#include "remote.h"
|
||||||
|
|
||||||
static git_remote *_remote;
|
static git_remote *_remote;
|
||||||
static git_repository *_repo;
|
static git_repository *_repo;
|
||||||
@ -33,10 +34,21 @@ void test_network_remotes__parsing(void)
|
|||||||
cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
|
cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
|
||||||
cl_assert(git_remote_pushurl(_remote) == NULL);
|
cl_assert(git_remote_pushurl(_remote) == NULL);
|
||||||
|
|
||||||
|
cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIR_FETCH),
|
||||||
|
"git://github.com/libgit2/libgit2");
|
||||||
|
cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIR_PUSH),
|
||||||
|
"git://github.com/libgit2/libgit2");
|
||||||
|
|
||||||
cl_git_pass(git_remote_load(&_remote2, _repo, "test_with_pushurl"));
|
cl_git_pass(git_remote_load(&_remote2, _repo, "test_with_pushurl"));
|
||||||
cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
|
cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
|
||||||
cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
|
cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
|
||||||
cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
|
cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
|
||||||
|
|
||||||
|
cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIR_FETCH),
|
||||||
|
"git://github.com/libgit2/fetchlibgit2");
|
||||||
|
cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIR_PUSH),
|
||||||
|
"git://github.com/libgit2/pushlibgit2");
|
||||||
|
|
||||||
git_remote_free(_remote2);
|
git_remote_free(_remote2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user