Module: Git::Repository::Merging Private
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/merging.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.
Facade methods for merge operations: merging branches into the current branch or into another branch, and finding common ancestors between commits
Included by Git::Repository.
Instance Method Summary collapse
-
#each_conflict {|file, your_version, their_version| ... } ⇒ Array<String>
private
Iterate over files with merge conflicts, yielding conflict details for each.
-
#merge(branch, message = nil, opts = {}) ⇒ String
private
Merge one or more branches into the current branch.
-
#merge_base(*commits, options = {}) ⇒ Array<String>
private
Find common ancestor commit(s) for use in a merge.
-
#merge_into(target_branch, branch, message = nil, opts = {}) ⇒ String
private
Merge one or more branches into another branch without leaving the current branch.
-
#revert(commitish = nil, opts = {}) ⇒ String
private
Revert one or more existing commits by creating new commits that undo the changes those commits introduced.
-
#unmerged ⇒ Array<String>
private
Return the paths of files with unresolved merge conflicts.
Instance Method Details
#each_conflict {|file, your_version, their_version| ... } ⇒ Array<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.
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.
305 306 307 308 309 310 311 312 313 |
# File 'lib/git/repository/merging.rb', line 305 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
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.
On a conflict, the merge is left in progress: the conflicted paths
are in the index and working tree, and MERGE_HEAD is set until the
caller commits the resolution or aborts the merge.
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/repository/merging.rb', line 89 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>
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.
Find common ancestor commit(s) for use in a merge
242 243 244 245 246 247 |
# File 'lib/git/repository/merging.rb', line 242 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 |
#merge_into(target_branch, branch, message = 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.
If the merge or the restore checkout fails, the repository is left
checked out on target_branch rather than restored to the original
branch. On a conflict, the merge is also left in progress. When the
restore checkout is the step that fails, the merge has already been
committed on target_branch.
Merge one or more branches into another branch without leaving the current branch
Records the current branch (or the current commit when HEAD is detached),
checks out target_branch, merges branch into it with #merge, then
checks out the original branch or commit again. Use #merge directly when
the target is the currently checked-out branch.
target_branch must be an existing local branch. Unlike Branching#checkout, a
commit SHA, tag, or remote-tracking branch is rejected before any checkout
happens: those detach HEAD, and the merge commit made there would be left
dangling once the original branch is restored while the named ref stayed
unchanged.
HEAD must be on a branch with at least one commit, or detached: an unborn branch (no commits yet) cannot be checked out again by name, so it is rejected before any checkout happens.
Option keys, the source list, and target_branch are checked before any
branch is checked out, so those failures never leave the repository on
target_branch. Anything rejected later, such as an option value that is
not accepted or a source ref that does not exist, surfaces inside #merge
after the checkout and leaves the repository checked out on target_branch.
The :no_commit option is not accepted: a merge stopped before its commit
would leave target_branch unchanged and the restore checkout would carry
the staged result onto the original branch. To merge without committing,
call Branching#checkout and #merge directly.
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/git/repository/merging.rb', line 188 def merge_into(target_branch, branch, = nil, opts = {}) SharedPrivate.assert_valid_opts!(MERGE_INTO_ALLOWED_OPTS, **opts) raise ArgumentError, 'at least one branch to merge is required' if Array(branch).empty? SharedPrivate.assert_local_branch!(self, target_branch) restore_point = SharedPrivate.head_restore_point(self) checkout(target_branch) output = merge(branch, , opts) # Runs only on success. See ADR-0009. checkout(restore_point) output end |
#revert(commitish = 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.
On a conflict, the revert is left in progress with the conflicted paths in the index and working tree until the caller continues, skips, or aborts it. When more than one commit is reverted, the revert commits made before the conflict are on the branch; aborting the revert removes them again.
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.
361 362 363 364 365 366 |
# File 'lib/git/repository/merging.rb', line 361 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 |
#unmerged ⇒ Array<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 paths of files with unresolved merge conflicts
263 264 265 |
# File 'lib/git/repository/merging.rb', line 263 def unmerged Private.unmerged_paths(@execution_context) end |