Commit d3cd7da51fc47d4dd864b398b6987472780aec43

Pierre-Olivier Latour 2014-10-28T20:56:18

Fixed active_refspecs field not initialized on new git_remote objects When creating a new remote, contrary to loading one from disk, active_refspecs was not populated. This means that if using the new remote to push, git_push_update_tips() will be a no-op since it checks the refspecs passed during the push against the base ones i.e. active_refspecs. And therefore the local refs won't be created or updated after the push operation.

diff --git a/src/remote.c b/src/remote.c
index cc9f85c..2897b45 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -163,6 +163,10 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
 	if (fetch != NULL) {
 		if (add_refspec(remote, fetch, true) < 0)
 			goto on_error;
+
+		/* Move the data over to where the matching functions can find them */
+		if (dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs) < 0)
+			goto on_error;
 	}
 
 	if (!name)
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index a69af64..2c8d02a 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -429,3 +429,38 @@ void test_network_remote_local__opportunistic_update(void)
 	cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/origin/master"));
 	git_reference_free(ref);
 }
+
+void test_network_remote_local__update_tips_for_new_remote(void) {
+	git_repository *src_repo;
+	git_repository *dst_repo;
+	git_remote *new_remote;
+	git_push *push;
+	git_reference* branch;
+
+	/* Copy test repo */
+	cl_fixture_sandbox("testrepo.git");
+	cl_git_pass(git_repository_open(&src_repo, "testrepo.git"));
+
+	/* Set up an empty bare repo to push into */
+	cl_git_pass(git_repository_init(&dst_repo, "./localbare.git", 1));
+
+	/* Push to bare repo */
+	cl_git_pass(git_remote_create(&new_remote, src_repo, "bare", "./localbare.git"));
+	cl_git_pass(git_remote_connect(new_remote, GIT_DIRECTION_PUSH));
+	cl_git_pass(git_push_new(&push, new_remote));
+	cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
+	cl_git_pass(git_push_finish(push));
+	cl_assert(git_push_unpack_ok(push));
+
+	/* Update tips and make sure remote branch has been created */
+	cl_git_pass(git_push_update_tips(push, NULL, NULL));
+	cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE));
+
+	git_reference_free(branch);
+	git_push_free(push);
+	git_remote_free(new_remote);
+	git_repository_free(dst_repo);
+	cl_fixture_cleanup("localbare.git");
+	git_repository_free(src_repo);
+	cl_fixture_cleanup("testrepo.git");
+}