Commit e16fc07f7e8c44b01fa61f66c2ad2c819484e248

nulltoken 2012-09-13T22:22:40

refspec: No remote tracking ref from a fetchspec-less remote

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