module Git::Repository::Branching::Private
Private helpers local to {Git::Repository::Branching}
@api private
Public Instance Methods
Source
# File lib/git/repository/branching.rb, line 846 def build_update_ref(branch) match = branch.match(%r{\A(?:refs/)?remotes/([^/]+)/(.+)\z}) match ? "refs/remotes/#{match[1]}/#{match[2]}" : "refs/heads/#{branch}" end
Builds the full git ref string from a branch name argument
Mirrors the routing logic of âGit::Branch#update_ref` for backward compatibility:
-
âremotes/<remote>/<name>` or `refs/remotes/<remote>/<name>` â`refs/remotes/<remote>/<name>`
-
Any other value â ârefs/heads/<branch>`
@param branch [String] a short local branch name or a remote-tracking
branch name with a `remotes/` or `refs/remotes/` prefix
@return [String] the full git ref string
@api private
Source
# File lib/git/repository/branching.rb, line 689 def get_branch_state(execution_context, branch_name) Git::Commands::RevParse.new(execution_context).call(branch_name, verify: true, quiet: true) :active rescue Git::FailedError => e raise unless e.result.status.exitstatus == 1 && e.result.stderr.empty? :unborn end
Determines whether the given branch ref points to an existing commit
Returns â:active` when the branch ref resolves successfully. Returns `:unborn` when the branch ref exists but has no commits yet (exit status 1 with empty stderr from `git rev-parse âverify âquiet`). Re-raises for any other failure.
@param execution_context [Git::ExecutionContext::Repository] the
execution context for git commands
@param branch_name [String] the branch name to verify
@return [:active, :unborn] the branch ref state
@raise [Git::FailedError] if git exits with a failure unrelated to an
unborn branch
@api private
Source
# File lib/git/repository/branching.rb, line 756 def normalize_orphan_option(checkout_options) orphan = checkout_options[:orphan] return checkout_options.except(:orphan) if orphan == false raise ArgumentError, 'orphan requires a non-empty branch name' if orphan.is_a?(String) && orphan.strip.empty? checkout_options end
Normalizes the â:orphan` option, rejecting names that git would never see
â:orphan` is a value option on the underlying command, so a literal `false` would be emitted as `âorphan false` and create a branch named âfalseâ. Flag options such as `:force` already ignore `false`; this gives `:orphan` the same behavior.
A blank name is rejected rather than dropped: the argument DSL omits empty values, so âorphan: â` would otherwise degrade silently into a plain checkout.
@param checkout_options [Hash] the raw options passed to {#checkout}
@return [Hash] the options with a âfalse` `:orphan` key removed
@raise [ArgumentError] if â:orphan` is given a blank branch name
@api private
Source
# File lib/git/repository/branching.rb, line 800 def normalize_pathspecs(pathspecs, arg_name) return nil unless pathspecs normalized = Array(pathspecs) validate_pathspec_types(normalized, arg_name) normalized = normalized.map(&:to_s).reject(&:empty?) return nil if normalized.empty? normalized end
Normalizes path specifications for Git commands
@param pathspecs [String, Pathname, Array<String, Pathname>, nil]
the path(s) to normalize
@param arg_name [String] the argument name used in error messages
@return [Array<String>, nil] the normalized paths, or ânil` if none are valid
@raise [ArgumentError] when any path is not a âString` or `Pathname`
@api private
Source
# File lib/git/repository/branching.rb, line 723 def translate_checkout_opts(branch, checkout_options) checkout_options = normalize_orphan_option(checkout_options) if checkout_options[:new_branch] == true || checkout_options[:b] == true [checkout_options[:start_point], checkout_options.except(:new_branch, :b, :start_point).merge(b: branch)] elsif checkout_options[:new_branch].is_a?(String) [branch, checkout_options.except(:new_branch).merge(b: checkout_options[:new_branch])] elsif checkout_options[:orphan] == true translate_orphan_opts(branch, checkout_options) else [branch, checkout_options] end end
Translates {#checkout} options to the new command interface
Legacy callers passed combinations like:
checkout('branch', new_branch: true, start_point: 'main')
which should map to:
checkout('main', b: 'branch')
âorphan: true` follows the same shape, naming the unborn branch:
checkout('branch', orphan: true, start_point: 'main')
maps to:
checkout('main', orphan: 'branch')
@param branch [String, nil] the branch argument passed to {#checkout}
@param checkout_options [Hash] the raw options passed to {#checkout}
@return [Array((String, nil), Hash)] a two-element tuple
`[target, options]` containing the translated checkout arguments `target` (`String` or `nil`) is the branch or commit to check out. `options` is a `Hash` of keyword arguments for `Git::Commands::Checkout::Branch#call`
@api private
Source
# File lib/git/repository/branching.rb, line 781 def translate_orphan_opts(branch, checkout_options) raise ArgumentError, 'orphan: true requires a branch name' if branch.to_s.strip.empty? [checkout_options[:start_point], checkout_options.except(:start_point).merge(orphan: branch)] end
Translates âorphan: true` into the commandâs â:orphan` value option
âorphan: true` names the unborn branch from the positional argument and takes its start point from `:start_point`, mirroring `new_branch: true`.
@param branch [String, nil] the branch argument passed to {#checkout}
@param checkout_options [Hash] the raw options passed to {#checkout}
@return [Array((String, nil), Hash)] a two-element tuple
`[target, options]` containing the translated checkout arguments
@raise [ArgumentError] if âbranch` is blank (`nil`, empty, or whitespace
only), since the unborn branch would otherwise have no name
@api private
Source
# File lib/git/repository/branching.rb, line 824 def validate_pathspec_types(pathspecs, arg_name) return if pathspecs.all? { |path| path.is_a?(String) || path.is_a?(Pathname) } raise ArgumentError, "Invalid #{arg_name}: must be a String, Pathname, or Array of Strings/Pathnames" end
Raises an error if any element of âpathspecs` is not a `String` or `Pathname`
@param pathspecs [Array] the path elements to validate
@param arg_name [String] the argument name used in error messages
@return [void]
@raise [ArgumentError] when any element is not a âString` or `Pathname`
@api private