Module: Git::Repository::Merging
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/merging.rb
Overview
Facade methods for merge operations: merging branches into the current branch, and finding common ancestors between commits
Included by Git::Repository.
Instance Method Summary collapse
-
#each_conflict {|file, your_version, their_version| ... } ⇒ Array<String>
Iterate over files with merge conflicts, yielding conflict details for each.
-
#merge(branch, message = nil, opts = {}) ⇒ String
Merge one or more branches into the current branch.
-
#merge_base(*commits, options = {}) ⇒ Array<String>
Find common ancestor commit(s) for use in a merge.
-
#revert(commitish = nil, opts = {}) ⇒ String
Revert one or more existing commits by creating new commits that undo the changes those commits introduced.
Instance Method Details
#each_conflict {|file, your_version, their_version| ... } ⇒ Array<String>
Iterate over files with merge conflicts, yielding conflict details for each
For each unmerged file, the staged content for both sides of the conflict (stage 2 "ours" and stage 3 "theirs") is written to temporary files whose paths are yielded alongside the file path. The temporary files are deleted automatically when the block returns.
182 183 184 185 186 187 188 189 190 |
# File 'lib/git/repository/merging.rb', line 182 def each_conflict Private.unmerged_paths(@execution_context).each do |file_path| Private.write_staged_file(@execution_context, file_path, 2) do |your_file| Private.write_staged_file(@execution_context, file_path, 3) do |their_file| yield(file_path, your_file.path, their_file.path) end end end end |
#merge(branch, message = nil, opts = {}) ⇒ String
Merge one or more branches into the current branch
The merge commit message may be given by the message positional argument, the
:message option, or the :m option; if more than one is provided, the
precedence is positional argument > :message > :m.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/git/repository/merging.rb', line 84 def merge(branch, = nil, opts = {}) SharedPrivate.assert_valid_opts!(MERGE_ALLOWED_OPTS, **opts) # Dup so callers who reuse the same opts hash are not affected opts = opts.dup # Merge positional message into opts so the rest of the logic is uniform opts[:message] = if # git merge uses -m, not --message; translate the key opts[:m] = opts.delete(:message) if opts.key?(:message) branches = Array(branch).map(&:to_s) Git::Commands::Merge::Start.new(@execution_context).call(*branches, no_edit: true, **opts).stdout end |
#merge_base(*commits, options = {}) ⇒ Array<String>
Find common ancestor commit(s) for use in a merge
141 142 143 144 145 146 |
# File 'lib/git/repository/merging.rb', line 141 def merge_base(*args) opts = args.last.is_a?(Hash) ? args.pop : {} SharedPrivate.assert_valid_opts!(MERGE_BASE_ALLOWED_OPTS, **opts) result = Git::Commands::MergeBase.new(@execution_context).call(*args, **opts) result.stdout.lines.map(&:strip).reject(&:empty?) end |
#revert(commitish = nil, opts = {}) ⇒ String
Revert one or more existing commits by creating new commits that undo the changes those commits introduced
The working tree must be clean before calling this method. By default
the editor is suppressed (--no-edit) so the commit message is taken
from git's default revert message without prompting.
232 233 234 235 236 237 |
# File 'lib/git/repository/merging.rb', line 232 def revert(commitish = nil, opts = {}) commitish = 'HEAD' if commitish.nil? SharedPrivate.assert_valid_opts!(REVERT_ALLOWED_OPTS, **opts) opts = { no_edit: true }.merge(opts) Git::Commands::Revert::Start.new(@execution_context).call(commitish, **opts).stdout end |