Class: Rugged::Remote
- Inherits:
-
Object
- Object
- Rugged::Remote
- Defined in:
- lib/rugged/remote.rb,
ext/rugged/rugged_remote.c
Instance Method Summary collapse
-
#check_connection(direction, options = {}) ⇒ Boolean
Try to connect to 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.
-
#url ⇒ String
Returns the remote’s url.
Instance Method Details
#check_connection(direction, options = {}) ⇒ Boolean
Try to connect to the remote
. Useful to simulate git fetch --dry-run
and git push --dry-run
.
Returns true
if connection is successful, false
otherwise.
direction
must be either :fetch
or :push
.
The following options can be passed in the options
Hash:
credentials
-
The credentials to use for the connection. 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. - :headers
-
Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
- :proxy_url
-
The url of an http proxy to use to access the remote repository.
Example:
remote = repo.remotes["origin"]
success = remote.check_connection(:fetch)
raise Error("Unable to pull without credentials") unless success
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'ext/rugged/rugged_remote.c', line 514
static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
{
git_remote *remote;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
git_proxy_options proxy_options = GIT_PROXY_OPTIONS_INIT;
git_strarray custom_headers = {0};
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
VALUE rb_direction, rb_options;
ID id_direction;
int error, direction;
Data_Get_Struct(self, git_remote, remote);
rb_scan_args(argc, argv, "01:", &rb_direction, &rb_options);
Check_Type(rb_direction, T_SYMBOL);
id_direction = SYM2ID(rb_direction);
if (id_direction == rb_intern("fetch"))
direction = GIT_DIRECTION_FETCH;
else if (id_direction == rb_intern("push"))
direction = GIT_DIRECTION_PUSH;
else
rb_raise(rb_eTypeError, "Invalid direction. Expected :fetch or :push");
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
rugged_remote_init_custom_headers(rb_options, &custom_headers);
rugged_remote_init_proxy_options(rb_options, &proxy_options);
error = git_remote_connect(remote, direction, &callbacks, &proxy_options, &custom_headers);
git_remote_disconnect(remote);
xfree(custom_headers.strings);
if (payload.exception)
rb_jump_tag(payload.exception);
return error ? Qfalse : Qtrue;
}
|
#fetch(refspecs = nil, options = {}) ⇒ Hash
Downloads new data from the remote for the given refspecs
and updates tips.
You can optionally pass in a single or multiple alternative 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. - :headers
-
Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
- :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
. - :certificate_check
-
A callback that will be executed each time we validate a certificate using https. It will be passed the
valid
,host_name
and the callback should return a true/false to indicate if the certificate has been validated. - :message
-
The message to insert into the reflogs. Defaults to “fetch”.
- :prune
-
Specifies the prune mode for the fetch.
true
remove any remote-tracking references that no longer exist,false
do not prune,nil
use configured settings Defaults to “nil”. - :proxy_url
-
The url of an http proxy to use to access the remote repository.
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|
# ...
}
})
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 663 664 665 666 667 |
# File 'ext/rugged/rugged_remote.c', line 611
static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
{
git_remote *remote;
git_strarray refspecs;
git_fetch_options opts = GIT_FETCH_OPTIONS_INIT;
const git_transfer_progress *stats;
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
char *log_message = NULL;
int error;
VALUE rb_options, rb_refspecs, rb_result = Qnil;
rb_scan_args(argc, argv, "01:", &rb_refspecs, &rb_options);
rugged_rb_ary_to_strarray(rb_refspecs, &refspecs);
Data_Get_Struct(self, git_remote, remote);
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
rugged_remote_init_proxy_options(rb_options, &opts.proxy_opts);
if (!NIL_P(rb_options)) {
VALUE rb_prune_type;
VALUE rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
if (!NIL_P(rb_val))
log_message = StringValueCStr(rb_val);
rb_prune_type = rb_hash_aref(rb_options, CSTR2SYM("prune"));
opts.prune = parse_prune_type(rb_prune_type);
}
error = git_remote_fetch(remote, &refspecs, &opts, log_message);
xfree(refspecs.strings);
xfree(opts.custom_headers.strings);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
stats = git_remote_stats(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));
return rb_result;
}
|
#fetch_refspecs ⇒ Object
remote.fetch_refspecs -> array
Get the remote’s list of fetch refspecs as array
.
466 467 468 469 |
# File 'ext/rugged/rugged_remote.c', line 466
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. - :headers
-
Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
- :proxy_url
-
The url of an http proxy to use to access the remote repository.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'ext/rugged/rugged_remote.c', line 313
static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
{
git_remote *remote;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
git_proxy_options proxy_options = GIT_PROXY_OPTIONS_INIT;
git_strarray custom_headers = {0};
const git_remote_head **heads;
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
VALUE rb_options;
int error;
size_t heads_len, i;
RETURN_ENUMERATOR(self, argc, argv);
Data_Get_Struct(self, git_remote, remote);
rb_scan_args(argc, argv, ":", &rb_options);
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
rugged_remote_init_custom_headers(rb_options, &custom_headers);
rugged_remote_init_proxy_options(rb_options, &proxy_options);
if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks, &proxy_options, &custom_headers)) ||
(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);
xfree(custom_headers.strings);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return Qnil;
}
|
#name ⇒ String
Returns the remote’s name.
remote.name #=> "origin"
364 365 366 367 368 369 370 371 372 373 |
# File 'ext/rugged/rugged_remote.c', line 364
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
. - :headers
-
Extra HTTP headers to include with the push (only applies to http:// or https:// remotes)
- :proxy_url
-
The url of an http proxy to use to access the remote repository.
- :pb_parallelism
-
Sets the number of worker threads that will be available to the packbuilder when generating a pack file, if required by the transport being used. A value of 0 means the packbuilder will auto-detect the number of of threads to use.
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 |
# 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;
git_remote *remote;
git_strarray refspecs;
git_push_options opts = GIT_PUSH_OPTIONS_INIT;
int error = 0;
struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, rb_hash_new(), 0 };
rb_scan_args(argc, argv, "01:", &rb_refspecs, &rb_options);
rugged_rb_ary_to_strarray(rb_refspecs, &refspecs);
Data_Get_Struct(self, git_remote, remote);
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
rugged_remote_init_proxy_options(rb_options, &opts.proxy_opts);
init_pb_parallelism(rb_options, &opts);
error = git_remote_push(remote, &refspecs, &opts);
xfree(refspecs.strings);
xfree(opts.custom_headers.strings);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return payload.result;
}
|
#push_refspecs ⇒ Object
remote.push_refspecs -> array
Get the remote’s list of push refspecs as array
.
477 478 479 480 |
# File 'ext/rugged/rugged_remote.c', line 477
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"
400 401 402 403 404 405 406 407 408 409 |
# File 'ext/rugged/rugged_remote.c', line 400
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"
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'ext/rugged/rugged_remote.c', line 420
static VALUE rb_git_remote_set_push_url(VALUE self, VALUE rb_url)
{
VALUE rb_repo = rugged_owner(self);
git_remote *remote;
git_repository *repo;
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_url, T_STRING);
Data_Get_Struct(self, git_remote, remote);
rugged_exception_check(
git_remote_set_pushurl(repo, git_remote_name(remote), StringValueCStr(rb_url))
);
return rb_url;
}
|
#url ⇒ String
Returns the remote’s url
remote.url #=> "git://github.com/libgit2/rugged.git"
383 384 385 386 387 388 389 |
# File 'ext/rugged/rugged_remote.c', line 383
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));
}
|