Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2013-01-17 19:20:33 +0400
committerJameson Miller <jamill@microsoft.com>2013-01-22 19:01:43 +0400
commit1d645aabefa6ac9f3f617acb7e3b9025aafcd750 (patch)
treed70abce426d026f872ea79745817afcdb9157f98 /src/push.c
parent47fc264203b2bae9e8a674505ac3502c3e9e71e7 (diff)
Update remote tips on push
Diffstat (limited to 'src/push.c')
-rw-r--r--src/push.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/push.c b/src/push.c
index 452ead405..ddfe5ec07 100644
--- a/src/push.c
+++ b/src/push.c
@@ -161,6 +161,60 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
+int git_push_update_tips(git_push *push)
+{
+ git_refspec *fetch_spec = &push->remote->fetch;
+ git_buf remote_ref_name = GIT_BUF_INIT;
+ size_t i, j;
+ push_spec *push_spec;
+ git_reference *remote_ref;
+ push_status *status;
+ int error = 0;
+
+ git_vector_foreach(&push->status, i, status) {
+ /* If this ref update was successful (ok, not ng), it will have an empty message */
+ if (status->msg)
+ continue;
+
+ /* Find the corresponding remote ref */
+ if (!git_refspec_src_matches(fetch_spec, status->ref))
+ continue;
+
+ if ((error = git_refspec_transform_r(&remote_ref_name, fetch_spec, status->ref)) < 0)
+ goto on_error;
+
+ /* Find matching push ref spec */
+ git_vector_foreach(&push->specs, j, push_spec) {
+ if (!strcmp(push_spec->rref, status->ref))
+ break;
+ }
+
+ /* Could not find the corresponding push ref spec for this push update */
+ if (j == push->specs.length)
+ continue;
+
+ /* Update the remote ref */
+ if (git_oid_iszero(&push_spec->loid)) {
+ error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
+
+ if (!error) {
+ if ((error = git_reference_delete(remote_ref)) < 0)
+ goto on_error;
+ } else if (error == GIT_ENOTFOUND)
+ 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)) < 0)
+ goto on_error;
+ }
+
+ error = 0;
+
+on_error:
+ git_buf_free(&remote_ref_name);
+ return error;
+}
+
static int revwalk(git_vector *commits, git_push *push)
{
git_remote_head *head;