refspec: No remote tracking ref from a fetchspec-less remote
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
diff --git a/src/branch.c b/src/branch.c
index cd5c10e..103dfe6 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -248,9 +248,11 @@ int git_branch_tracking(
goto cleanup;
refspec = git_remote_fetchspec(remote);
- if (refspec == NULL) {
- error = GIT_ENOTFOUND;
- goto cleanup;
+ if (refspec == NULL
+ || refspec->src == NULL
+ || refspec->dst == NULL) {
+ error = GIT_ENOTFOUND;
+ goto cleanup;
}
if (git_refspec_transform_r(&buf, refspec, merge_name) < 0)
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 63016db..3ff6197 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -107,7 +107,7 @@ void test_network_remotelocal__retrieve_advertised_references(void)
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 25);
+ cl_assert_equal_i(how_many_refs, 26);
}
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
@@ -121,7 +121,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 25);
+ cl_assert_equal_i(how_many_refs, 26);
git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
remote = NULL;
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index f1d6f47..c7ee863 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -186,13 +186,13 @@ void test_network_remotes__list(void)
git_config *cfg;
cl_git_pass(git_remote_list(&list, _repo));
- cl_assert(list.count == 2);
+ cl_assert(list.count == 3);
git_strarray_free(&list);
cl_git_pass(git_repository_config(&cfg, _repo));
cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
cl_git_pass(git_remote_list(&list, _repo));
- cl_assert(list.count == 3);
+ cl_assert(list.count == 4);
git_strarray_free(&list);
git_config_free(cfg);
diff --git a/tests-clar/refs/branches/foreach.c b/tests-clar/refs/branches/foreach.c
index aca11ec..92d5b1f 100644
--- a/tests-clar/refs/branches/foreach.c
+++ b/tests-clar/refs/branches/foreach.c
@@ -47,7 +47,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count)
void test_refs_branches_foreach__retrieve_all_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 13);
+ assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 14);
}
void test_refs_branches_foreach__retrieve_remote_branches(void)
@@ -57,7 +57,7 @@ void test_refs_branches_foreach__retrieve_remote_branches(void)
void test_refs_branches_foreach__retrieve_local_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL, 11);
+ assert_retrieval(GIT_BRANCH_LOCAL, 12);
}
struct expectations {
diff --git a/tests-clar/refs/branches/tracking.c b/tests-clar/refs/branches/tracking.c
index 8f70194..9cf435e 100644
--- a/tests-clar/refs/branches/tracking.c
+++ b/tests-clar/refs/branches/tracking.c
@@ -67,3 +67,14 @@ void test_refs_branches_tracking__trying_to_retrieve_a_remote_tracking_reference
git_reference_free(branch);
}
+
+void test_refs_branches_tracking__trying_to_retrieve_a_remote_tracking_reference_from_a_branch_with_no_fetchspec_returns_GIT_ENOTFOUND(void)
+{
+ git_reference *branch, *tracking;
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/cannot-fetch"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_tracking(&tracking, branch));
+
+ git_reference_free(branch);
+}
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
index 054846f..1213429 100644
--- a/tests-clar/refs/foreachglob.c
+++ b/tests-clar/refs/foreachglob.c
@@ -46,7 +46,7 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_
void test_refs_foreachglob__retrieve_all_refs(void)
{
/* 8 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
- assert_retrieval("*", GIT_REF_LISTALL, 20);
+ assert_retrieval("*", GIT_REF_LISTALL, 21);
}
void test_refs_foreachglob__retrieve_remote_branches(void)
@@ -56,7 +56,7 @@ void test_refs_foreachglob__retrieve_remote_branches(void)
void test_refs_foreachglob__retrieve_local_branches(void)
{
- assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 11);
+ assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 12);
}
void test_refs_foreachglob__retrieve_partially_named_references(void)
diff --git a/tests-clar/resources/testrepo.git/config b/tests-clar/resources/testrepo.git/config
index 04ab387..54ff610 100644
--- a/tests-clar/resources/testrepo.git/config
+++ b/tests-clar/resources/testrepo.git/config
@@ -6,6 +6,8 @@
[remote "test"]
url = git://github.com/libgit2/libgit2
fetch = +refs/heads/*:refs/remotes/test/*
+[remote "joshaber"]
+ url = git://github.com/libgit2/libgit2
[remote "test_with_pushurl"]
url = git://github.com/libgit2/fetchlibgit2
@@ -18,3 +20,6 @@
[branch "track-local"]
remote = .
merge = refs/heads/master
+[branch "cannot-fetch"]
+ remote = joshaber
+ merge = refs/heads/cannot-fetch
diff --git a/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch b/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch
new file mode 100644
index 0000000..aab87e5
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/cannot-fetch
@@ -0,0 +1 @@
+a4a7dce85cf63874e984719f4fdd239f5145052f