Commit c587d806e7b7ae0b64ae387b253d41dfdfbdc98d

Patrick Steinhardt 2018-04-12T09:11:26

Merge pull request #4613 from pks-t/pks/local-fetch-symrefs transports: local: fix assert when fetching into repo with symrefs

diff --git a/src/transports/local.c b/src/transports/local.c
index 740cf36..0178407 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -510,8 +510,12 @@ static int local_counting(int stage, unsigned int current, unsigned int total, v
 static int foreach_reference_cb(git_reference *reference, void *payload)
 {
 	git_revwalk *walk = (git_revwalk *)payload;
+	int error;
+
+	if (git_reference_type(reference) != GIT_REF_OID)
+		return 0;
 
-	int error = git_revwalk_hide(walk, git_reference_target(reference));
+	error = git_revwalk_hide(walk, git_reference_target(reference));
 	/* The reference is in the local repository, so the target may not
 	 * exist on the remote.  It also may not be a commit. */
 	if (error == GIT_ENOTFOUND || error == GITERR_INVALID) {
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 4dabb57..a639460 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -343,6 +343,29 @@ void test_fetchhead_nonetwork__unborn_with_upstream(void)
 	cl_fixture_cleanup("./repowithunborn");
 }
 
+void test_fetchhead_nonetwork__fetch_into_repo_with_symrefs(void)
+{
+	git_repository *repo;
+	git_remote *remote;
+	git_reference *symref;
+
+	repo = cl_git_sandbox_init("empty_standard_repo");
+
+	/*
+	 * Testing for a specific constellation where the repository has at
+	 * least one symbolic reference in its refdb.
+	 */
+	cl_git_pass(git_reference_symbolic_create(&symref, repo, "refs/heads/symref", "refs/heads/master", 0, NULL));
+
+	cl_git_pass(git_remote_set_url(repo, "origin", cl_fixture("testrepo.git")));
+	cl_git_pass(git_remote_lookup(&remote, repo, "origin"));
+	cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+
+	git_remote_free(remote);
+	git_reference_free(symref);
+	cl_git_sandbox_cleanup();
+}
+
 void test_fetchhead_nonetwork__quote_in_branch_name(void)
 {
 	cl_set_cleanup(&cleanup_repository, "./test1");