Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b5b814

Browse files
committed
Merge pull request libgit2#2671 from swisspol/remote_create_fix
Fixed active_refspecs field not initialized on new git_remote objects
2 parents 7f1b73b + d3cd7da commit 8b5b814

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
163163
if (fetch != NULL) {
164164
if (add_refspec(remote, fetch, true) < 0)
165165
goto on_error;
166+
167+
/* Move the data over to where the matching functions can find them */
168+
if (dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs) < 0)
169+
goto on_error;
166170
}
167171

168172
if (!name)

tests/network/remote/local.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,38 @@ void test_network_remote_local__opportunistic_update(void)
429429
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/origin/master"));
430430
git_reference_free(ref);
431431
}
432+
433+
void test_network_remote_local__update_tips_for_new_remote(void) {
434+
git_repository *src_repo;
435+
git_repository *dst_repo;
436+
git_remote *new_remote;
437+
git_push *push;
438+
git_reference* branch;
439+
440+
/* Copy test repo */
441+
cl_fixture_sandbox("testrepo.git");
442+
cl_git_pass(git_repository_open(&src_repo, "testrepo.git"));
443+
444+
/* Set up an empty bare repo to push into */
445+
cl_git_pass(git_repository_init(&dst_repo, "./localbare.git", 1));
446+
447+
/* Push to bare repo */
448+
cl_git_pass(git_remote_create(&new_remote, src_repo, "bare", "./localbare.git"));
449+
cl_git_pass(git_remote_connect(new_remote, GIT_DIRECTION_PUSH));
450+
cl_git_pass(git_push_new(&push, new_remote));
451+
cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
452+
cl_git_pass(git_push_finish(push));
453+
cl_assert(git_push_unpack_ok(push));
454+
455+
/* Update tips and make sure remote branch has been created */
456+
cl_git_pass(git_push_update_tips(push, NULL, NULL));
457+
cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE));
458+
459+
git_reference_free(branch);
460+
git_push_free(push);
461+
git_remote_free(new_remote);
462+
git_repository_free(dst_repo);
463+
cl_fixture_cleanup("localbare.git");
464+
git_repository_free(src_repo);
465+
cl_fixture_cleanup("testrepo.git");
466+
}

0 commit comments

Comments
 (0)