Module: Git::Repository::RemoteOperations
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/remote_operations.rb
Overview
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
Register a new remote in the local repository.
-
#config_remote(name) ⇒ Hash{String => String}
Return the git configuration entries for a named remote.
-
#fetch(remote = 'origin', opts = {}) ⇒ String
Download objects and refs from a remote repository.
-
#pull(remote = nil, branch = nil, opts = {}) ⇒ String
Incorporate changes from a remote repository into the current branch.
-
#push(remote = nil, branch = nil, opts = nil)
Push refs to a remote repository.
-
#remote(name = 'origin') ⇒ Git::Remote
Returns a Git::Remote object for the named remote.
-
#remote_set_branches(name, *branches, add: false)
Configures which branches are fetched for a remote.
-
#remotes ⇒ Array<Git::Remote>
Returns all configured remotes as Git::Remote objects.
-
#remove_remote(name) ⇒ Git::CommandLineResult
Removes a remote from this repository.
-
#set_remote_url(name, url) ⇒ Git::Remote
Sets the URL for an existing remote.
Instance Method Details
#add_remote(name, url, opts = {}) ⇒ Git::Remote
Register a new remote in the local repository
Associates name with url and optionally fetches immediately or
configures which branches are tracked.
417 418 419 420 421 422 423 424 |
# File 'lib/git/repository/remote_operations.rb', line 417 def add_remote(name, url, opts = {}) url = url.repo.to_s if url.is_a?(Git::Base) opts = Private.normalize_add_remote_keys(opts) SharedPrivate.assert_valid_opts!(ADD_REMOTE_ALLOWED_OPTS, **opts) Git::Commands::Remote::Add.new(@execution_context).call(name, url, **opts) Git::Remote.new(self, name) end |
#config_remote(name) ⇒ Hash{String => String}
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.
532 533 534 535 536 537 |
# File 'lib/git/repository/remote_operations.rb', line 532 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
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 |
#pull(remote = nil, branch = nil, opts = {}) ⇒ String
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.
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/git/repository/remote_operations.rb', line 196 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(options = {}) ⇒ String #push(remote, options = {}) ⇒ String #push(remote, branch, options = {}) ⇒ String #push(remote, branch, tags) ⇒ String
Push refs to a remote repository
362 363 364 365 366 367 368 369 370 371 |
# File 'lib/git/repository/remote_operations.rb', line 362 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
Returns a Git::Remote object for the named remote
553 554 555 |
# File 'lib/git/repository/remote_operations.rb', line 553 def remote(name = 'origin') Git::Remote.new(self, name) end |
#remote_set_branches(name, *branches, add: false)
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.
501 502 503 504 505 506 507 508 |
# File 'lib/git/repository/remote_operations.rb', line 501 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 |
#remotes ⇒ Array<Git::Remote>
Returns all configured remotes as Git::Remote objects
568 569 570 571 |
# File 'lib/git/repository/remote_operations.rb', line 568 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::CommandLineResult
Removes a remote from this repository
Deletes the remote named name along with its associated configuration,
tracking references, and remote-tracking branches.
440 441 442 |
# File 'lib/git/repository/remote_operations.rb', line 440 def remove_remote(name) Git::Commands::Remote::Remove.new(@execution_context).call(name) end |
#set_remote_url(name, url) ⇒ Git::Remote
Sets the URL for an existing remote
Replaces the fetch URL configured for the remote named name.
466 467 468 469 470 471 |
# File 'lib/git/repository/remote_operations.rb', line 466 def set_remote_url(name, url) url = url.repo.to_s if url.is_a?(Git::Base) Git::Commands::Remote::SetUrl.new(@execution_context).call(name, url) Git::Remote.new(self, name) end |