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.
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
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");
+}