Add reflog parameters to git_push_update_tips
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
diff --git a/include/git2/push.h b/include/git2/push.h
index 12f0e7f..c98c6d9 100644
--- a/include/git2/push.h
+++ b/include/git2/push.h
@@ -103,10 +103,16 @@ GIT_EXTERN(int) git_push_add_refspec(git_push *push, const char *refspec);
* Update remote tips after a push
*
* @param push The push object
+ * @param signature The identity to use when updating reflogs
+ * @param reflog_message The message to insert into the reflogs. If NULL, the
+ * default is "update by push".
*
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_push_update_tips(git_push *push);
+GIT_EXTERN(int) git_push_update_tips(
+ git_push *push,
+ const git_signature *signature,
+ const char *reflog_message);
/**
* Actually push all given refspecs
diff --git a/src/push.c b/src/push.c
index d39a271..c294780 100644
--- a/src/push.c
+++ b/src/push.c
@@ -194,7 +194,10 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
-int git_push_update_tips(git_push *push)
+int git_push_update_tips(
+ git_push *push,
+ const git_signature *signature,
+ const char *reflog_message)
{
git_buf remote_ref_name = GIT_BUF_INIT;
size_t i, j;
@@ -241,7 +244,9 @@ int git_push_update_tips(git_push *push)
giterr_clear();
else
goto on_error;
- } else if ((error = git_reference_create(NULL, push->remote->repo, git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, NULL, NULL)) < 0)
+ } else if ((error = git_reference_create(NULL, push->remote->repo,
+ git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
+ reflog_message ? reflog_message : "update by push")) < 0)
goto on_error;
}
diff --git a/tests/online/push.c b/tests/online/push.c
index 8efe21e..c0ff2f2 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -414,11 +414,13 @@ static void do_push(
git_push_options opts = GIT_PUSH_OPTIONS_INIT;
size_t i;
int pack_progress_calls = 0, transfer_progress_calls = 0;
+ git_signature *pusher;
if (_remote) {
/* Auto-detect the number of threads to use */
opts.pb_parallelism = 0;
+ cl_git_pass(git_signature_now(&pusher, "Foo Bar", "foo@example.com"));
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
cl_git_pass(git_push_new(&push, _remote));
@@ -455,13 +457,15 @@ static void do_push(
verify_refs(_remote, expected_refs, expected_refs_len);
- cl_git_pass(git_push_update_tips(push));
+ cl_git_pass(git_push_update_tips(push, pusher, "test push"));
verify_tracking_branches(_remote, expected_refs, expected_refs_len);
git_push_free(push);
git_remote_disconnect(_remote);
+ git_signature_free(pusher);
}
+
}
/* Call push_finish() without ever calling git_push_add_refspec() */
@@ -528,6 +532,9 @@ void test_online_push__b5_cancel(void)
void test_online_push__multi(void)
{
+ git_reflog *log;
+ const git_reflog_entry *entry;
+
const char *specs[] = {
"refs/heads/b1:refs/heads/b1",
"refs/heads/b2:refs/heads/b2",
@@ -552,6 +559,13 @@ void test_online_push__multi(void)
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+
+ cl_git_pass(git_reflog_read(&log, _repo, "refs/remotes/test/b1"));
+ entry = git_reflog_entry_byindex(log, 0);
+ cl_assert_equal_s("test push", git_reflog_entry_message(entry));
+ cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
+
+ git_reflog_free(log);
}
void test_online_push__implicit_tgt(void)