Skip to content

Commit 1551b1f

Browse files
authored
Merge pull request libgit2#6226 from libgit2/cmn/update-tips-error
remote: do store the update_tips callback error value
2 parents 83f2a20 + e35b5e4 commit 1551b1f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ static int update_one_tip(
18521852
}
18531853

18541854
if (callbacks && callbacks->update_tips != NULL &&
1855-
callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload) < 0)
1855+
(error = callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload)) < 0)
18561856
git_error_set_after_callback_function(error, "git_remote_fetch");
18571857

18581858
done:

tests/network/fetchlocal.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,44 @@ void test_network_fetchlocal__prune_load_fetch_prune_config(void)
509509
git_remote_free(origin);
510510
git_repository_free(repo);
511511
}
512+
513+
static int update_tips_error(const char *ref, const git_oid *old, const git_oid *new, void *data)
514+
{
515+
int *callcount = (int *) data;
516+
517+
GIT_UNUSED(ref);
518+
GIT_UNUSED(old);
519+
GIT_UNUSED(new);
520+
521+
(*callcount)++;
522+
523+
return -1;
524+
}
525+
526+
void test_network_fetchlocal__update_tips_error_is_propagated(void)
527+
{
528+
git_repository *repo;
529+
git_reference_iterator *iterator;
530+
git_reference *ref;
531+
git_remote *remote;
532+
git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
533+
int callcount = 0;
534+
535+
cl_git_pass(git_repository_init(&repo, "foo.git", true));
536+
cl_set_cleanup(cleanup_local_repo, "foo.git");
537+
538+
cl_git_pass(git_remote_create_with_fetchspec(&remote, repo, "origin", cl_git_fixture_url("testrepo.git"), "+refs/heads/*:refs/remotes/update-tips/*"));
539+
540+
options.callbacks.update_tips = update_tips_error;
541+
options.callbacks.payload = &callcount;
542+
543+
cl_git_fail(git_remote_fetch(remote, NULL, &options, NULL));
544+
cl_assert_equal_i(1, callcount);
545+
546+
cl_git_pass(git_reference_iterator_glob_new(&iterator, repo, "refs/remotes/update-tips/**/"));
547+
cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iterator));
548+
549+
git_reference_iterator_free(iterator);
550+
git_remote_free(remote);
551+
git_repository_free(repo);
552+
}

0 commit comments

Comments
 (0)