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 772 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 674 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 726 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 703 def translate_checkout_opts(branch, 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])] else [branch, checkout_options] end end
Translates legacy 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')
@param branch [String, nil] the branch argument passed to {#checkout}
@param checkout_options [Hash] the raw options passed to {#checkout}
@return [Array] 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 750 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