Class: Rugged::Remote
- Inherits:
-
Object
- Object
- Rugged::Remote
- Defined in:
- lib/rugged/remote.rb,
ext/rugged/rugged_remote.c
Instance Method Summary collapse
-
#add_fetch(refspec) ⇒ nil
Add a fetch refspec to the remote.
-
#add_push(refspec) ⇒ nil
Add a push refspec to the remote.
-
#clear_refspecs ⇒ nil
Remove all configured fetch and push refspecs from the remote.
-
#fetch(refspecs = nil, options = {}) ⇒ Hash
Downloads new data from the remote for the given
refspecs
and updates tips. -
#fetch_refspecs ⇒ Object
remote.fetch_refspecs -> array.
-
#ls(*args) ⇒ Object
Connects
remote
to list all references available along with their associated commit ids. -
#name ⇒ String
Returns the remote’s name.
-
#push(refspecs = nil, options = {}) ⇒ Hash
Pushes the given
refspecs
to the givenremote
. -
#push_refspecs ⇒ Object
remote.push_refspecs -> array.
-
#push_url ⇒ String?
Returns the remote’s url for pushing or nil if no special url for pushing is set.
-
#push_url=(url) ⇒ Object
Sets the remote’s url for pushing without persisting it in the config.
-
#rename!(new_name) ⇒ Array?
Renames a remote.
-
#save ⇒ true
Saves the remote data (url, fetchspecs, …) to the config.
-
#url ⇒ String
Returns the remote’s url.
-
#url=(url) ⇒ Object
Sets the remote’s url without persisting it in the config.
Instance Method Details
#add_fetch(refspec) ⇒ nil
Add a fetch refspec to the remote.
445 446 447 448 |
# File 'ext/rugged/rugged_remote.c', line 445
static VALUE rb_git_remote_add_fetch(VALUE self, VALUE rb_refspec)
{
return rb_git_remote_add_refspec(self, rb_refspec, GIT_DIRECTION_FETCH);
}
|
#add_push(refspec) ⇒ nil
Add a push refspec to the remote.
456 457 458 459 |
# File 'ext/rugged/rugged_remote.c', line 456
static VALUE rb_git_remote_add_push(VALUE self, VALUE rb_refspec)
{
return rb_git_remote_add_refspec(self, rb_refspec, GIT_DIRECTION_PUSH);
}
|
#clear_refspecs ⇒ nil
Remove all configured fetch and push refspecs from the remote.
467 468 469 470 471 472 473 474 475 476 |
# File 'ext/rugged/rugged_remote.c', line 467
static VALUE rb_git_remote_clear_refspecs(VALUE self)
{
git_remote *remote;
Data_Get_Struct(self, git_remote, remote);
git_remote_clear_refspecs(remote);
return Qnil;
}
|
#fetch(refspecs = nil, options = {}) ⇒ Hash
Downloads new data from the remote for the given refspecs
and updates tips.
You can optionally pass in an alternative list of refspecs
to use instead of the fetch refspecs already configured for remote
.
Returns a hash containing statistics for the fetch operation.
The following options can be passed in the options
Hash:
- :credentials
-
The credentials to use for the fetch 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
, theusername
from the url (if applicable) and a list of applicable credential types. - :progress
-
A callback that will be executed with the textual progress received from the remote. This is the text send over the progress side-band (ie. the “counting objects” output).
- :transfer_progress
-
A callback that will be executed to report clone progress information. It will be passed the amount of
total_objects
,indexed_objects
,received_objects
,local_objects
,total_deltas
,indexed_deltas
andreceived_bytes
. - :update_tips
-
A callback that will be executed each time a reference is updated locally. It will be passed the
refname
,old_oid
andnew_oid
. - :message
-
The message to insert into the reflogs. Defaults to “fetch”.
- :signature
-
The signature to be used for updating the reflogs.
Example:
remote = Rugged::Remote.lookup(@repo, 'origin')
remote.fetch({
transfer_progress: lambda { |total_objects, indexed_objects, received_objects, local_objects, total_deltas, indexed_deltas, received_bytes|
# ...
}
})
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'ext/rugged/rugged_remote.c', line 585
static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
{
git_remote *remote, *tmp_remote = NULL;
git_repository *repo;
git_signature *signature = NULL;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
char *log_message = NULL;
int error, i;
VALUE rb_options, rb_refspecs, rb_result = Qnil, rb_repo = rugged_owner(self);
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);
}
}
Data_Get_Struct(self, git_remote, remote);
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
if (!NIL_P(rb_options)) {
VALUE rb_val = rb_hash_aref(rb_options, CSTR2SYM("signature"));
if (!NIL_P(rb_val))
signature = rugged_signature_get(rb_val, repo);
rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
if (!NIL_P(rb_val))
log_message = StringValueCStr(rb_val);
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
}
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_fetch(tmp_remote, StringValueCStr(rb_refspec))))
goto cleanup;
}
}
if ((error = git_remote_fetch(tmp_remote, signature, log_message)) == GIT_OK) {
const git_transfer_progress *stats = git_remote_stats(tmp_remote);
rb_result = rb_hash_new();
rb_hash_aset(rb_result, CSTR2SYM("total_objects"), UINT2NUM(stats->total_objects));
rb_hash_aset(rb_result, CSTR2SYM("indexed_objects"), UINT2NUM(stats->indexed_objects));
rb_hash_aset(rb_result, CSTR2SYM("received_objects"), UINT2NUM(stats->received_objects));
rb_hash_aset(rb_result, CSTR2SYM("local_objects"), UINT2NUM(stats->local_objects));
rb_hash_aset(rb_result, CSTR2SYM("total_deltas"), UINT2NUM(stats->total_deltas));
rb_hash_aset(rb_result, CSTR2SYM("indexed_deltas"), UINT2NUM(stats->indexed_deltas));
rb_hash_aset(rb_result, CSTR2SYM("received_bytes"), INT2FIX(stats->received_bytes));
}
cleanup:
git_signature_free(signature);
git_remote_free(tmp_remote);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return rb_result;
}
|
#fetch_refspecs ⇒ Object
remote.fetch_refspecs -> array
Get the remote’s list of fetch refspecs as array
.
404 405 406 407 |
# File 'ext/rugged/rugged_remote.c', line 404
static VALUE rb_git_remote_fetch_refspecs(VALUE self)
{
return rb_git_remote_refspecs(self, GIT_DIRECTION_FETCH);
}
|
#ls(options = {}) ⇒ Object #ls(options = ) { ... } ⇒ Object
Connects remote
to list all references available along with their associated commit ids.
The given block is called once for each remote head with a Hash containing the following keys:
- :local?
-
true
if the remote head is available locally,false
otherwise. - :oid
-
The id of the object the remote head is currently pointing to.
- :loid
-
The id of the object the local copy of the remote head is currently pointing to. Set to
nil
if there is no local copy of the remote head. - :name
-
The fully qualified reference name of the remote head.
If no block is given, an enumerator will be returned.
The following options can be passed in the options
Hash:
- :credentials
-
The credentials to use for the ls 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
, theusername
from the url (if applicable) and a list of applicable credential types.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'ext/rugged/rugged_remote.c', line 234
static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
{
git_remote *remote;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
const git_remote_head **heads;
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
VALUE rb_options;
int error;
size_t heads_len, i;
Data_Get_Struct(self, git_remote, remote);
rb_scan_args(argc, argv, ":", &rb_options);
if (!rb_block_given_p())
return rb_funcall(self, rb_intern("to_enum"), 2, CSTR2SYM("ls"), rb_options);
if (!NIL_P(rb_options))
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
if ((error = git_remote_set_callbacks(remote, &callbacks)) ||
(error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) ||
(error = git_remote_ls(&heads, &heads_len, remote)))
goto cleanup;
for (i = 0; i < heads_len && !payload.exception; i++)
rb_protect(rb_yield, rugged_rhead_new(heads[i]), &payload.exception);
cleanup:
git_remote_disconnect(remote);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return Qnil;
}
|
#name ⇒ String
Returns the remote’s name.
remote.name #=> "origin"
285 286 287 288 289 290 291 292 293 294 |
# File 'ext/rugged/rugged_remote.c', line 285
static VALUE rb_git_remote_name(VALUE self)
{
git_remote *remote;
const char * name;
Data_Get_Struct(self, git_remote, remote);
name = git_remote_name(remote);
return name ? rb_str_new_utf8(name) : Qnil;
}
|
#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.
You can optionally pass in an alternative list of refspecs
to use instead of the push refspecs already configured for remote
.
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
, theusername
from the url (if applicable) and a list of applicable credential types. - :update_tips
-
A callback that will be executed each time a reference is updated remotely. It will be passed the
refname
,old_oid
andnew_oid
. - :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"])
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'ext/rugged/rugged_remote.c', line 707
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;
}
|
#push_refspecs ⇒ Object
remote.push_refspecs -> array
Get the remote’s list of push refspecs as array
.
415 416 417 418 |
# File 'ext/rugged/rugged_remote.c', line 415
static VALUE rb_git_remote_push_refspecs(VALUE self)
{
return rb_git_remote_refspecs(self, GIT_DIRECTION_PUSH);
}
|
#push_url ⇒ String?
Returns the remote’s url for pushing or nil if no special url for pushing is set.
remote.push_url #=> "git://github.com/libgit2/rugged.git"
343 344 345 346 347 348 349 350 351 352 |
# File 'ext/rugged/rugged_remote.c', line 343
static VALUE rb_git_remote_push_url(VALUE self)
{
git_remote *remote;
const char * push_url;
Data_Get_Struct(self, git_remote, remote);
push_url = git_remote_pushurl(remote);
return push_url ? rb_str_new_utf8(push_url) : Qnil;
}
|
#push_url=(url) ⇒ Object
Sets the remote’s url for pushing without persisting it in the config. Existing connections will not be updated.
remote.push_url = '[email protected]/libgit2/rugged.git' #=> "[email protected]/libgit2/rugged.git"
363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'ext/rugged/rugged_remote.c', line 363
static VALUE rb_git_remote_set_push_url(VALUE self, VALUE rb_url)
{
git_remote *remote;
rugged_validate_remote_url(rb_url);
Data_Get_Struct(self, git_remote, remote);
rugged_exception_check(
git_remote_set_pushurl(remote, StringValueCStr(rb_url))
);
return rb_url;
}
|
#rename!(new_name) ⇒ Array?
Renames a remote.
All remote-tracking branches and configuration settings for the remote are updated.
Returns nil
if everything was updated or array of fetch refspecs that haven’t been automatically updated and need potential manual tweaking.
Anonymous, in-memory remotes created through ReferenceCollection#create_anonymous can not be given a name through this method.
remote = Rugged::Remote.lookup(@repo, 'origin')
remote.rename!('upstream') #=> nil
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'ext/rugged/rugged_remote.c', line 520
static VALUE rb_git_remote_rename(VALUE self, VALUE rb_new_name)
{
git_remote *remote;
git_strarray problems = {0};
VALUE rb_result;
Check_Type(rb_new_name, T_STRING);
Data_Get_Struct(self, git_remote, remote);
rugged_exception_check(
git_remote_rename(&problems, remote, StringValueCStr(rb_new_name))
);
rb_result = problems.count == 0 ? Qnil : rugged_strarray_to_rb_ary(&problems);
git_strarray_free(&problems);
return rb_result;
}
|
#save ⇒ true
Saves the remote data (url, fetchspecs, …) to the config.
Anonymous, in-memory remotes created through ReferenceCollection#create_anonymous can not be saved. Doing so will result in an exception being raised.
488 489 490 491 492 493 494 495 496 497 498 |
# File 'ext/rugged/rugged_remote.c', line 488
static VALUE rb_git_remote_save(VALUE self)
{
git_remote *remote;
Data_Get_Struct(self, git_remote, remote);
rugged_exception_check(
git_remote_save(remote)
);
return Qtrue;
}
|
#url ⇒ String
Returns the remote’s url
remote.url #=> "git://github.com/libgit2/rugged.git"
304 305 306 307 308 309 310 |
# File 'ext/rugged/rugged_remote.c', line 304
static VALUE rb_git_remote_url(VALUE self)
{
git_remote *remote;
Data_Get_Struct(self, git_remote, remote);
return rb_str_new_utf8(git_remote_url(remote));
}
|
#url=(url) ⇒ Object
Sets the remote’s url without persisting it in the config. Existing connections will not be updated.
remote.url = 'git://github.com/libgit2/rugged.git' #=> "git://github.com/libgit2/rugged.git"
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'ext/rugged/rugged_remote.c', line 321
static VALUE rb_git_remote_set_url(VALUE self, VALUE rb_url)
{
git_remote *remote;
rugged_validate_remote_url(rb_url);
Data_Get_Struct(self, git_remote, remote);
rugged_exception_check(
git_remote_set_url(remote, StringValueCStr(rb_url))
);
return rb_url;
}
|