git_remote_ls() should return an error if the transport is not available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/remote.c b/src/remote.c
index e9dafa0..433015f 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -699,6 +699,11 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
{
assert(remote);
+ if (!remote->transport) {
+ giterr_set(GITERR_NET, "No transport bound to this remote");
+ return -1;
+ }
+
return remote->transport->ls(out, size, remote->transport);
}
@@ -1942,6 +1947,8 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
size_t heads_len, i;
int error;
+ assert(out);
+
if ((error = git_remote_ls(&heads, &heads_len, remote)) < 0)
return error;
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index 75f7679..f1084fc 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -55,6 +55,17 @@ void test_network_remote_local__retrieve_advertised_references(void)
cl_assert_equal_i(refs_len, 28);
}
+void test_network_remote_local__retrieve_advertised_before_connect(void)
+{
+ const git_remote_head **refs;
+ size_t refs_len = 0;
+
+ git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
+
+ cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
+ cl_git_fail(git_remote_ls(&refs, &refs_len, remote));
+}
+
void test_network_remote_local__retrieve_advertised_references_after_disconnect(void)
{
const git_remote_head **refs;