void test_network_remote_remotes__query_refspecs(void) { git_remote *remote; git_strarray array; int i; cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "query", "git://github.com/libgit2/libgit2", NULL)); git_remote_free(remote); for (i = 0; i < 3; i++) { cl_git_pass(git_remote_add_fetch(_repo, "query", fetch_refspecs[i])); cl_git_pass(git_remote_add_push(_repo, "query", push_refspecs[i])); } cl_git_pass(git_remote_lookup(&remote, _repo, "query")); cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); for (i = 0; i < 3; i++) { cl_assert_equal_s(fetch_refspecs[i], array.strings[i]); } git_strarray_free(&array); cl_git_pass(git_remote_get_push_refspecs(&array, remote)); for (i = 0; i < 3; i++) { cl_assert_equal_s(push_refspecs[i], array.strings[i]); } git_strarray_free(&array); git_remote_free(remote); git_remote_delete(_repo, "test"); }
emacs_value egit_remote_add_refspec( emacs_env *env, emacs_value _repo, emacs_value _name, emacs_value _refspec, emacs_value direction) { EGIT_ASSERT_REPOSITORY(_repo); EM_ASSERT_STRING(_name); EM_ASSERT_STRING(_refspec); bool push; if (EM_EQ(direction, em_push)) push = true; else if (EM_EQ(direction, em_fetch)) push = false; else { em_signal_wrong_value(env, direction); return em_nil; } git_repository *repo = EGIT_EXTRACT(_repo); char *name = EM_EXTRACT_STRING(_name); char *refspec = EM_EXTRACT_STRING(_refspec); int retval = push ? git_remote_add_push(repo, name, refspec) : git_remote_add_fetch(repo, name, refspec); free(name); free(refspec); EGIT_CHECK_ERROR(retval); return em_nil; }
void GitRepository::push() { git_repository* repo = repository(); const char* remote_name = "origin"; git_auto<git_remote> remote; git_eval(git_remote_lookup(&remote, repo, remote_name)); git_eval(git_remote_connect(remote, GIT_DIRECTION_PUSH, NULL, NULL)); git_auto<git_reference> head; git_eval(git_repository_head(&head, repo)); QString refname = QString("+%1:%1").arg(git_reference_name(head)); git_eval(git_remote_add_push(repo, remote_name, refname.toLatin1())); git_eval(git_remote_upload(remote, NULL, NULL)); }
PyObject * Remote_add_push(Remote *self, PyObject *args) { git_remote *remote; char *refspec = NULL; int err = 0; if (!PyArg_ParseTuple(args, "s", &refspec)) return NULL; remote = self->remote; err = git_remote_add_push(remote, refspec); if (err < 0) return Error_set(err); Py_RETURN_NONE; }
static VALUE rb_git_remote_add_refspec(VALUE self, VALUE rb_refspec, git_direction direction) { git_remote *remote; int error = 0; Data_Get_Struct(self, git_remote, remote); Check_Type(rb_refspec, T_STRING); if (direction == GIT_DIRECTION_FETCH) error = git_remote_add_fetch(remote, StringValueCStr(rb_refspec)); else error = git_remote_add_push(remote, StringValueCStr(rb_refspec)); rugged_exception_check(error); return Qnil; }
void test_network_remote_remotes__add_pushspec(void) { size_t size; size = git_remote_refspec_count(_remote); cl_git_pass(git_remote_add_push(_repo, "test", "refs/*:refs/*")); size++; git_remote_free(_remote); cl_git_pass(git_remote_lookup(&_remote, _repo, "test")); cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote)); _refspec = git_remote_get_refspec(_remote, size - 1); cl_assert_equal_s(git_refspec_src(_refspec), "refs/*"); cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*"); cl_assert_equal_b(_refspec->push, true); }
/* * call-seq: * remote.push(refspecs = nil, options = {}) -> hash * * Pushes the given +refspecs+ to the given +remote+. Returns a hash that contains * key-value pairs that reflect pushed refs and error messages, if applicable. * * The following options can be passed in the +options+ Hash: * * :credentials :: * The credentials to use for the push operation. Can be either an instance of one * of the Rugged::Credentials types, or a proc returning one of the former. * The proc will be called with the +url+, the +username+ from the url (if applicable) and * a list of applicable credential types. * * :message :: * A single line log message to be appended to the reflog of each local remote-tracking * branch that gets updated. Defaults to: "fetch". * * :signature :: * The signature to be used for populating the reflog entries. * * Example: * * remote = Rugged::Remote.lookup(@repo, 'origin') * remote.push(["refs/heads/master", ":refs/heads/to_be_deleted"]) */ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self) { VALUE rb_refspecs, rb_options, rb_val; VALUE rb_repo = rugged_owner(self); VALUE rb_exception = Qnil, rb_result = rb_hash_new(); git_repository *repo; git_remote *remote, *tmp_remote = NULL; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; git_push *push = NULL; git_signature *signature = NULL; int error = 0, i = 0; char *log_message = NULL; struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, 0 }; rb_scan_args(argc, argv, "01:", &rb_refspecs, &rb_options); if (!NIL_P(rb_refspecs)) { Check_Type(rb_refspecs, T_ARRAY); for (i = 0; i < RARRAY_LEN(rb_refspecs); ++i) { VALUE rb_refspec = rb_ary_entry(rb_refspecs, i); Check_Type(rb_refspec, T_STRING); } } rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Data_Get_Struct(self, git_remote, remote); if (!NIL_P(rb_options)) { rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload); rb_val = rb_hash_aref(rb_options, CSTR2SYM("message")); if (!NIL_P(rb_val)) log_message = StringValueCStr(rb_val); rb_val = rb_hash_aref(rb_options, CSTR2SYM("signature")); if (!NIL_P(rb_val)) signature = rugged_signature_get(rb_val, repo); } // Create a temporary remote that we use for pushing if ((error = git_remote_dup(&tmp_remote, remote)) || (error = git_remote_set_callbacks(tmp_remote, &callbacks))) goto cleanup; if (!NIL_P(rb_refspecs)) { git_remote_clear_refspecs(tmp_remote); for (i = 0; !error && i < RARRAY_LEN(rb_refspecs); ++i) { VALUE rb_refspec = rb_ary_entry(rb_refspecs, i); if ((error = git_remote_add_push(tmp_remote, StringValueCStr(rb_refspec)))) goto cleanup; } } if ((error = git_push_new(&push, tmp_remote))) goto cleanup; // TODO: Get rid of this once git_remote_push lands in libgit2. { git_strarray push_refspecs; size_t i; if ((error = git_remote_get_push_refspecs(&push_refspecs, tmp_remote))) goto cleanup; if (push_refspecs.count == 0) { rb_exception = rb_exc_new2(rb_eRuggedError, "no pushspecs are configured for the given remote"); goto cleanup; } for (i = 0; !error && i < push_refspecs.count; ++i) { error = git_push_add_refspec(push, push_refspecs.strings[i]); } git_strarray_free(&push_refspecs); if (error) goto cleanup; } if ((error = git_push_finish(push))) goto cleanup; if (!git_push_unpack_ok(push)) { rb_exception = rb_exc_new2(rb_eRuggedError, "the remote side did not unpack successfully"); goto cleanup; } if ((error = git_push_status_foreach(push, &push_status_cb, (void *)rb_result)) || (error = git_push_update_tips(push, signature, log_message))) goto cleanup; cleanup: git_push_free(push); git_remote_free(tmp_remote); git_signature_free(signature); if (!NIL_P(rb_exception)) rb_exc_raise(rb_exception); rugged_exception_check(error); return rb_result; }