mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-19 20:36:44 +00:00
Correct default reflog message for git_remote_fetch
This commit is contained in:
parent
2bfc673910
commit
db55bb73ff
@ -357,7 +357,8 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote);
|
||||
* @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"
|
||||
* default is "fetch <name>", where <name> is the name of
|
||||
* the remote (or its url, for in-memory remotes).
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_update_tips(
|
||||
|
13
src/remote.c
13
src/remote.c
@ -851,6 +851,7 @@ int git_remote_fetch(
|
||||
const char *reflog_message)
|
||||
{
|
||||
int error;
|
||||
git_buf reflog_msg_buf = GIT_BUF_INIT;
|
||||
|
||||
/* Connect and download everything */
|
||||
if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) != 0)
|
||||
@ -862,8 +863,18 @@ int git_remote_fetch(
|
||||
/* We don't need to be connected anymore */
|
||||
git_remote_disconnect(remote);
|
||||
|
||||
/* Default reflog message */
|
||||
if (reflog_message)
|
||||
git_buf_sets(&reflog_msg_buf, reflog_message);
|
||||
else {
|
||||
git_buf_printf(&reflog_msg_buf, "fetch %s",
|
||||
remote->name ? remote->name : remote->url);
|
||||
}
|
||||
|
||||
/* Create "remote/foo" branches for all remote branches */
|
||||
return git_remote_update_tips(remote, signature, reflog_message);
|
||||
error = git_remote_update_tips(remote, signature, git_buf_cstr(&reflog_msg_buf));
|
||||
git_buf_free(&reflog_msg_buf);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
|
||||
|
@ -328,3 +328,31 @@ void test_network_remote_local__reflog(void)
|
||||
git_reflog_free(log);
|
||||
git_signature_free(sig);
|
||||
}
|
||||
|
||||
void test_network_remote_local__fetch_default_reflog_message(void)
|
||||
{
|
||||
const char *refspec = "master:remotes/sloppy/master";
|
||||
|
||||
git_reflog *log;
|
||||
const git_reflog_entry *entry;
|
||||
git_signature *sig;
|
||||
char expected_reflog_msg[1024];
|
||||
|
||||
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, NULL));
|
||||
|
||||
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);
|
||||
|
||||
sprintf(expected_reflog_msg, "fetch %s", git_remote_url(remote));
|
||||
cl_assert_equal_s(expected_reflog_msg, git_reflog_entry_message(entry));
|
||||
|
||||
git_reflog_free(log);
|
||||
git_signature_free(sig);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user