Commit c3ab1e5a by Ben Straub

Add reflog parameters to remote apis

Also added a test for git_remote_fetch.
parent 491cecfe
...@@ -355,9 +355,15 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote); ...@@ -355,9 +355,15 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote);
* Update the tips to the new state * Update the tips to the new state
* *
* @param remote the remote to update * @param remote the remote to update
* @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch"
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_remote_update_tips(git_remote *remote); GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote,
const git_signature *signature,
const char *reflog_message);
/** /**
* Download new data and update tips * Download new data and update tips
...@@ -366,9 +372,15 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote); ...@@ -366,9 +372,15 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
* disconnect and update the remote-tracking branches. * disconnect and update the remote-tracking branches.
* *
* @param remote the remote to fetch from * @param remote the remote to fetch from
* @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch"
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_remote_fetch(git_remote *remote); GIT_EXTERN(int) git_remote_fetch(
git_remote *remote,
const git_signature *signature,
const char *reflog_message);
/** /**
* Return whether a string is a valid remote URL * Return whether a string is a valid remote URL
......
...@@ -360,7 +360,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_ ...@@ -360,7 +360,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_
git_remote_set_update_fetchhead(remote, 0); git_remote_set_update_fetchhead(remote, 0);
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
if ((error = git_remote_fetch(remote)) != 0) if ((error = git_remote_fetch(remote, signature, git_buf_cstr(&reflog_message))) != 0)
goto cleanup; goto cleanup;
if (branch) if (branch)
......
...@@ -845,7 +845,10 @@ int git_remote_download(git_remote *remote) ...@@ -845,7 +845,10 @@ int git_remote_download(git_remote *remote)
return git_fetch_download_pack(remote); return git_fetch_download_pack(remote);
} }
int git_remote_fetch(git_remote *remote) int git_remote_fetch(
git_remote *remote,
const git_signature *signature,
const char *reflog_message)
{ {
int error; int error;
...@@ -860,7 +863,7 @@ int git_remote_fetch(git_remote *remote) ...@@ -860,7 +863,7 @@ int git_remote_fetch(git_remote *remote)
git_remote_disconnect(remote); git_remote_disconnect(remote);
/* Create "remote/foo" branches for all remote branches */ /* Create "remote/foo" branches for all remote branches */
return git_remote_update_tips(remote); return git_remote_update_tips(remote, signature, reflog_message);
} }
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src) static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
...@@ -978,7 +981,12 @@ cleanup: ...@@ -978,7 +981,12 @@ cleanup:
return error; return error;
} }
static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vector *refs) static int update_tips_for_spec(
git_remote *remote,
git_refspec *spec,
git_vector *refs,
const git_signature *signature,
const char *log_message)
{ {
int error = 0, autotag; int error = 0, autotag;
unsigned int i = 0; unsigned int i = 0;
...@@ -1045,7 +1053,8 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto ...@@ -1045,7 +1053,8 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto
continue; continue;
/* In autotag mode, don't overwrite any locally-existing tags */ /* In autotag mode, don't overwrite any locally-existing tags */
error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag, NULL, NULL); error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
signature, log_message);
if (error < 0 && error != GIT_EEXISTS) if (error < 0 && error != GIT_EEXISTS)
goto on_error; goto on_error;
...@@ -1074,7 +1083,10 @@ on_error: ...@@ -1074,7 +1083,10 @@ on_error:
} }
int git_remote_update_tips(git_remote *remote) int git_remote_update_tips(
git_remote *remote,
const git_signature *signature,
const char *reflog_message)
{ {
git_refspec *spec, tagspec; git_refspec *spec, tagspec;
git_vector refs; git_vector refs;
...@@ -1089,7 +1101,7 @@ int git_remote_update_tips(git_remote *remote) ...@@ -1089,7 +1101,7 @@ int git_remote_update_tips(git_remote *remote)
goto out; goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) { if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
error = update_tips_for_spec(remote, &tagspec, &refs); error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message);
goto out; goto out;
} }
...@@ -1097,7 +1109,7 @@ int git_remote_update_tips(git_remote *remote) ...@@ -1097,7 +1109,7 @@ int git_remote_update_tips(git_remote *remote)
if (spec->push) if (spec->push)
continue; continue;
if ((error = update_tips_for_spec(remote, spec, &refs)) < 0) if ((error = update_tips_for_spec(remote, spec, &refs, signature, reflog_message)) < 0)
goto out; goto out;
} }
......
...@@ -37,7 +37,7 @@ void test_network_fetchlocal__complete(void) ...@@ -37,7 +37,7 @@ void test_network_fetchlocal__complete(void)
git_remote_set_callbacks(origin, &callbacks); git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin)); cl_git_pass(git_remote_download(origin));
cl_git_pass(git_remote_update_tips(origin)); cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
cl_git_pass(git_reference_list(&refnames, repo)); cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count); cl_assert_equal_i(19, (int)refnames.count);
...@@ -75,7 +75,7 @@ void test_network_fetchlocal__partial(void) ...@@ -75,7 +75,7 @@ void test_network_fetchlocal__partial(void)
git_remote_set_callbacks(origin, &callbacks); git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin)); cl_git_pass(git_remote_download(origin));
cl_git_pass(git_remote_update_tips(origin)); cl_git_pass(git_remote_update_tips(origin, NULL, NULL));
git_strarray_free(&refnames); git_strarray_free(&refnames);
......
...@@ -115,7 +115,7 @@ void test_network_remote_local__shorthand_fetch_refspec0(void) ...@@ -115,7 +115,7 @@ void test_network_remote_local__shorthand_fetch_refspec0(void)
cl_git_pass(git_remote_add_fetch(remote, refspec2)); cl_git_pass(git_remote_add_fetch(remote, refspec2));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master")); cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref); git_reference_free(ref);
...@@ -137,7 +137,7 @@ void test_network_remote_local__shorthand_fetch_refspec1(void) ...@@ -137,7 +137,7 @@ void test_network_remote_local__shorthand_fetch_refspec1(void)
cl_git_pass(git_remote_add_fetch(remote, refspec2)); cl_git_pass(git_remote_add_fetch(remote, refspec2));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master")); cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master"));
...@@ -152,7 +152,7 @@ void test_network_remote_local__tagopt(void) ...@@ -152,7 +152,7 @@ void test_network_remote_local__tagopt(void)
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL); git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master")); cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master"));
...@@ -171,7 +171,7 @@ void test_network_remote_local__push_to_bare_remote(void) ...@@ -171,7 +171,7 @@ void test_network_remote_local__push_to_bare_remote(void)
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, "master:master")); cl_git_pass(git_remote_add_fetch(remote, "master:master"));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */ /* Set up an empty bare repo to push into */
...@@ -208,7 +208,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void) ...@@ -208,7 +208,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, "master:master")); cl_git_pass(git_remote_add_fetch(remote, "master:master"));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */ /* Set up an empty bare repo to push into */
...@@ -248,7 +248,7 @@ void test_network_remote_local__push_to_non_bare_remote(void) ...@@ -248,7 +248,7 @@ void test_network_remote_local__push_to_non_bare_remote(void)
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, "master:master")); cl_git_pass(git_remote_add_fetch(remote, "master:master"));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
/* Set up an empty non-bare repo to push into */ /* Set up an empty non-bare repo to push into */
...@@ -273,3 +273,58 @@ void test_network_remote_local__push_to_non_bare_remote(void) ...@@ -273,3 +273,58 @@ void test_network_remote_local__push_to_non_bare_remote(void)
git_remote_free(localremote); git_remote_free(localremote);
cl_fixture_cleanup("localbare.git"); cl_fixture_cleanup("localbare.git");
} }
void test_network_remote_local__fetch(void)
{
const char *refspec = "master:remotes/sloppy/master";
git_reflog *log;
const git_reflog_entry *entry;
git_signature *sig;
git_reference *ref;
cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, refspec));
cl_git_pass(git_remote_fetch(remote, sig, "UPDAAAAAATE!!"));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref);
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
cl_assert_equal_s("UPDAAAAAATE!!", git_reflog_entry_message(entry));
git_reflog_free(log);
git_signature_free(sig);
}
void test_network_remote_local__reflog(void)
{
const char *refspec = "master:remotes/sloppy/master";
git_reflog *log;
const git_reflog_entry *entry;
git_signature *sig;
cl_git_pass(git_signature_now(&sig, "Foo Bar", "foo@example.com"));
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, refspec));
cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote, sig, "UPDAAAAAATE!!"));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
cl_assert_equal_s("UPDAAAAAATE!!", git_reflog_entry_message(entry));
git_reflog_free(log);
git_signature_free(sig);
}
...@@ -48,7 +48,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n) ...@@ -48,7 +48,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
git_remote_set_autotag(remote, flag); git_remote_set_autotag(remote, flag);
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
cl_assert_equal_i(counter, n); cl_assert_equal_i(counter, n);
cl_assert(bytes_received > 0); cl_assert(bytes_received > 0);
...@@ -117,7 +117,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date ...@@ -117,7 +117,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_assert_equal_i(false, invoked); cl_assert_equal_i(false, invoked);
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
git_remote_free(remote); git_remote_free(remote);
......
...@@ -51,7 +51,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet ...@@ -51,7 +51,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(remote)); cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote)); cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote); git_remote_disconnect(remote);
git_remote_free(remote); git_remote_free(remote);
......
...@@ -351,7 +351,7 @@ void test_online_push__initialize(void) ...@@ -351,7 +351,7 @@ void test_online_push__initialize(void)
/* Now that we've deleted everything, fetch from the remote */ /* Now that we've deleted everything, fetch from the remote */
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(_remote)); cl_git_pass(git_remote_download(_remote));
cl_git_pass(git_remote_update_tips(_remote)); cl_git_pass(git_remote_update_tips(_remote, NULL, NULL));
git_remote_disconnect(_remote); git_remote_disconnect(_remote);
} else } else
printf("GITTEST_REMOTE_URL unset; skipping push test\n"); printf("GITTEST_REMOTE_URL unset; skipping push test\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment