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
-
#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_add(name, url, opts = {})
private
Register a new remote in the local repository.
-
#remote_list ⇒ Array<Git::RemoteInfo>
private
List all configured remotes as Git::RemoteInfo objects.
-
#remote_names ⇒ Array<String>
Returns the names of all configured remotes.
-
#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)
private
Sets the URL for an existing remote.
Instance Method Details
#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.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/git/repository/remote_operations.rb', line 128 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.
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.
549 550 551 552 553 554 |
# File 'lib/git/repository/remote_operations.rb', line 549 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.
The fetch completes before the merge starts, so a failure after the
fetch leaves FETCH_HEAD and any updated remote-tracking branches in
place. On a conflict, the merge is left in progress as described at
Merging#merge, or the rebase when the repository is configured to pull with
rebase.
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.
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/git/repository/remote_operations.rb', line 199 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
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/git/repository/remote_operations.rb', line 289 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_add(name, url, opts = {})
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.
Register a new remote in the local repository
Associates name with url and optionally fetches immediately or
configures which branches are tracked.
344 345 346 347 348 349 350 351 |
# File 'lib/git/repository/remote_operations.rb', line 344 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) nil end |
#remote_list ⇒ Array<Git::RemoteInfo>
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.
List all configured remotes as Git::RemoteInfo objects
Reads the repository configuration via Configuring#config_list and
returns one Git::RemoteInfo per configured remote, preserving the order
in which remotes appear in the config. Multi-value fields (:url,
:push_url, :fetch, :push) are always Array<String> (never nil).
461 462 463 |
# File 'lib/git/repository/remote_operations.rb', line 461 def remote_list Git::Parsers::Remote.parse_list(config_list) end |
#remote_names ⇒ Array<String>
Returns the names of all configured remotes
Lists remote names by running git remote. This is a lightweight
alternative to #remote_list when only names are needed — in
particular, it returns the raw name (e.g. "team/upstream") preserving
any slashes in the remote name.
486 487 488 |
# File 'lib/git/repository/remote_operations.rb', line 486 def remote_names Git::Commands::Remote::List.new(@execution_context).call.stdout.split("\n") 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.
367 368 369 |
# File 'lib/git/repository/remote_operations.rb', line 367 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.
428 429 430 431 432 433 434 435 |
# File 'lib/git/repository/remote_operations.rb', line 428 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)
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.
Sets the URL for an existing remote
Replaces the fetch URL configured for the remote named name.
393 394 395 396 397 398 |
# File 'lib/git/repository/remote_operations.rb', line 393 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) nil end |