Module: Git::Repository::RemoteOperations Private
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/remote_operations.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Mixin that adds remote operation facade methods to Git::Repository
Included by Git::Repository.
Instance Method Summary collapse
-
#add_remote(name, url, opts = {}) ⇒ Git::Remote
deprecated
private
Deprecated.
Use #remote_add instead
-
#config_remote(name) ⇒ Hash{String => String}
private
Return the git configuration entries for a named remote.
-
#fetch(remote = 'origin', opts = {}) ⇒ String
private
Download objects and refs from a remote repository.
-
#ls_remote(location = nil, opts = {}) ⇒ Hash{String => Hash}
private
List references available in a remote repository.
-
#pull(remote = nil, branch = nil, opts = {}) ⇒ String
private
Incorporate changes from a remote repository into the current branch.
-
#push(remote = nil, branch = nil, opts = nil) ⇒ String
private
Push refs to a remote repository.
-
#remote(name = 'origin') ⇒ Git::Remote
private
Returns a Git::Remote object for the named remote.
-
#remote_add(name, url, opts = {}) ⇒ Git::Remote
private
Register a new remote in the local repository.
-
#remote_remove(name) ⇒ Git::CommandLine::Result
private
Removes a remote from this repository.
-
#remote_set_branches(name, *branches, add: false)
private
Configures which branches are fetched for a remote.
-
#remote_set_url(name, url) ⇒ Git::Remote
private
Sets the URL for an existing remote.
-
#remotes ⇒ Array<Git::Remote>
private
Returns all configured remotes as Git::Remote objects.
-
#remove_remote(name) ⇒ Git::CommandLine::Result
deprecated
private
Deprecated.
Use #remote_remove instead
-
#set_remote_url(name, url) ⇒ Git::Remote
deprecated
private
Deprecated.
Use #remote_set_url instead
Instance Method Details
#add_remote(name, url, opts = {}) ⇒ Git::Remote
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #remote_add instead
Returns the newly added remote.
374 375 376 377 378 379 380 |
# File 'lib/git/repository/remote_operations.rb', line 374 def add_remote(name, url, opts = {}) Git::Deprecation.warn( 'Git::Repository#add_remote is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#remote_add instead.' ) remote_add(name, url, opts) end |
#config_remote(name) ⇒ Hash{String => String}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the git configuration entries for a named remote
Reads git config --list and returns all entries whose keys begin with
remote.<name>., with the remote.<name>. prefix stripped. This
typically yields at least "url" and "fetch" for a configured remote.
525 526 527 528 529 530 |
# File 'lib/git/repository/remote_operations.rb', line 525 def config_remote(name) prefix = "remote.#{name}." Private.config_list(@execution_context).each_with_object({}) do |(key, value), hsh| hsh[key.delete_prefix(prefix)] = value if key.start_with?(prefix) end end |
#fetch(remote = 'origin', opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Download objects and refs from a remote repository
Fetches branches and/or tags from one or more other repositories, along with the objects necessary to complete their histories. The local tracking references are updated but the working directory is not modified.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/git/repository/remote_operations.rb', line 129 def fetch(remote = 'origin', opts = {}) remote, opts = Private.resolve_fetch_target(remote, opts) opts = Private.normalize_fetch_keys(opts) SharedPrivate.assert_valid_opts!(FETCH_ALLOWED_OPTS, **opts) opts = opts.dup refspecs = Array(opts.delete(:ref)).compact positionals = [*([remote] if remote), *refspecs] Git::Commands::Fetch.new(@execution_context).call(*positionals, **opts, merge: true).stdout end |
#ls_remote(location = nil, opts = {}) ⇒ Hash{String => Hash}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The :ref value in each pair is only the first path segment of the
full git ref (e.g. "refs" for refs/heads/main), not the complete ref
path. This matches the behavior of 4.x. See
issue 1416 for the
planned fix.
List references available in a remote repository
Queries a remote for its available refs and returns a structured Hash mapping ref types to name/sha pairs. The remote is contacted but no local objects are created or updated.
631 632 633 634 635 636 |
# File 'lib/git/repository/remote_operations.rb', line 631 def ls_remote(location = nil, opts = {}) SharedPrivate.assert_valid_opts!(LS_REMOTE_ALLOWED_OPTS, **opts) repository = location || '.' output_lines = Git::Commands::LsRemote.new(@execution_context).call(repository, **opts).stdout.split("\n") Git::Parsers::LsRemote.parse_output(output_lines) end |
#pull(remote = nil, branch = nil, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Incorporate changes from a remote repository into the current branch
Fetches from the given remote and merges into the current branch. In its
default mode, git pull is shorthand for git fetch followed by
git merge FETCH_HEAD. The merge editor is suppressed (--no-edit) and
progress output is silenced (--no-progress) by default.
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/git/repository/remote_operations.rb', line 194 def pull(remote = nil, branch = nil, opts = {}) raise ArgumentError, 'You must specify a remote if a branch is specified' if remote.nil? && !branch.nil? SharedPrivate.assert_valid_opts!(PULL_ALLOWED_OPTS, **opts) positional_args = [remote, branch].compact Git::Commands::Pull .new(@execution_context) .call(*positional_args, no_edit: true, no_progress: true, **opts) .stdout end |
#push(remote = nil, branch = nil, opts = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Push refs to a remote repository
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/git/repository/remote_operations.rb', line 284 def push(remote = nil, branch = nil, opts = nil) remote, branch, opts = Private.normalize_push_args(remote, branch, opts) SharedPrivate.assert_valid_opts!(PUSH_ALLOWED_OPTS, **opts) raise ArgumentError, 'remote is required if branch is specified' if !remote && branch first_result = Private.push_refs(@execution_context, remote, branch, opts) return first_result.stdout unless Private.(opts) Private.(@execution_context, remote, opts).stdout end |
#remote(name = 'origin') ⇒ Git::Remote
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a Git::Remote object for the named remote
546 547 548 |
# File 'lib/git/repository/remote_operations.rb', line 546 def remote(name = 'origin') Git::Remote.new(self, name) end |
#remote_add(name, url, opts = {}) ⇒ Git::Remote
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a new remote in the local repository
Associates name with url and optionally fetches immediately or
configures which branches are tracked.
339 340 341 342 343 344 345 346 |
# File 'lib/git/repository/remote_operations.rb', line 339 def remote_add(name, url, opts = {}) url = url.repo.to_s if url.is_a?(Git::Repository) opts = Private.normalize_add_remote_keys(opts) SharedPrivate.assert_valid_opts!(REMOTE_ADD_ALLOWED_OPTS, **opts) Git::Commands::Remote::Add.new(@execution_context).call(name, url, **opts) Git::Remote.new(self, name) end |
#remote_remove(name) ⇒ Git::CommandLine::Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes a remote from this repository
Deletes the remote named name along with its associated configuration,
tracking references, and remote-tracking branches.
396 397 398 |
# File 'lib/git/repository/remote_operations.rb', line 396 def remote_remove(name) Git::Commands::Remote::Remove.new(@execution_context).call(name) end |
#remote_set_branches(name, *branches, add: false)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Configures which branches are fetched for a remote
Uses git remote set-branches to set or append fetch refspecs. When the
add: option is false, the --add flag is not passed to the git
command and the tracked branch list is replaced.
494 495 496 497 498 499 500 501 |
# File 'lib/git/repository/remote_operations.rb', line 494 def remote_set_branches(name, *branches, add: false) branch_list = branches.flatten raise ArgumentError, 'branches are required' if branch_list.empty? Git::Commands::Remote::SetBranches.new(@execution_context).call(name, *branch_list, add: add) nil end |
#remote_set_url(name, url) ⇒ Git::Remote
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the URL for an existing remote
Replaces the fetch URL configured for the remote named name.
438 439 440 441 442 443 |
# File 'lib/git/repository/remote_operations.rb', line 438 def remote_set_url(name, url) url = url.repo.to_s if url.is_a?(Git::Repository) Git::Commands::Remote::SetUrl.new(@execution_context).call(name, url) Git::Remote.new(self, name) end |
#remotes ⇒ Array<Git::Remote>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all configured remotes as Git::Remote objects
561 562 563 564 |
# File 'lib/git/repository/remote_operations.rb', line 561 def remotes result = Git::Commands::Remote::List.new(@execution_context).call result.stdout.split("\n").map { |name| Git::Remote.new(self, name) } end |
#remove_remote(name) ⇒ Git::CommandLine::Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #remote_remove instead
Returns the result of calling git remote remove.
408 409 410 411 412 413 414 |
# File 'lib/git/repository/remote_operations.rb', line 408 def remove_remote(name) Git::Deprecation.warn( 'Git::Repository#remove_remote is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#remote_remove instead.' ) remote_remove(name) end |
#set_remote_url(name, url) ⇒ Git::Remote
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #remote_set_url instead
Returns the updated remote.
458 459 460 461 462 463 464 |
# File 'lib/git/repository/remote_operations.rb', line 458 def set_remote_url(name, url) Git::Deprecation.warn( 'Git::Repository#set_remote_url is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#remote_set_url instead.' ) remote_set_url(name, url) end |