module Git::Repository::Stashing::Private
Private helpers local to {Git::Repository::Stashing}
@api private
Public Instance Methods
Source
# File lib/git/repository/stashing.rb, line 557 def resolve_commit_oid(execution_context, commit) raise ArgumentError, 'commit is required' if commit.nil? commit = commit.to_s raise ArgumentError, "Invalid commit: '#{commit}'" if commit.start_with?('-', '^') revision = commit.start_with?(':/') ? commit : "#{commit}^{commit}" Git::Commands::RevParse.new(execution_context).call(revision, verify: true).stdout.strip end
Resolve a commit-ish to the full object id of the commit it names
The revision is peeled with ‘git rev-parse –verify <commit>^{commit}`, so an annotated tag yields the tagged commit, an abbreviated or uppercase id yields the full lowercase id, and an id that names no object fails (a bare `–verify <id>` echoes a well-formed id back without looking it up). A `:/<text>` search consumes the rest of the revision string, so it is passed without the suffix; such a search only ever names a commit. {Git::Repository::ObjectOperations#rev_parse} is not used because it runs `–revs-only`, which prints both ends of a range and exits zero instead of failing.
{Git::Commands::RevParse} places its operand after ‘–end-of-options`, so the arguments DSL does not reject a `nil` or option-like operand, and `–verify` accepts a negated revision such as `^HEAD` and prints the id back with its caret. This method raises `ArgumentError` for all three before running git.
@example With an annotated tag
Private.resolve_commit_oid(execution_context, 'v1.0.0') #=> "9b9b31e704c0b85ffdd8d2af2ded85170a5af87d"
@example With a range
Private.resolve_commit_oid(execution_context, 'main..topic') #=> raises Git::FailedError
@param execution_context [Git::ExecutionContext] the context to run git in
@param commit [String, to_s] a revision that resolves to a commit or
peels to one
@return [String] the full object id of the commit
@raise [ArgumentError] if ‘commit` is `nil` or starts with a hyphen or a
caret
@raise [Git::FailedError] when ‘commit` does not resolve to a single
revision or does not peel to a commit
Source
# File lib/git/repository/stashing.rb, line 610 def split_pathspec_and_opts(pathspec) return [pathspec[0...-1], pathspec.last] if pathspec.last.is_a?(Hash) [pathspec, {}] end
Separate a trailing options Hash from a pathspec list
{Git::Repository::Stashing#stash_push} takes a variadic pathspec, so its options arrive as the last positional argument when present.
@example Pathspecs followed by options
Private.split_pathspec_and_opts(['a.rb', { message: 'WIP' }]) #=> [["a.rb"], { message: "WIP" }]
@example Pathspecs only
Private.split_pathspec_and_opts(['a.rb']) #=> [["a.rb"], {}]
@param pathspec [Array<String, Hash>] the positional arguments, possibly
ending in an options Hash
@return [Array(Array<String>, Hash)] the pathspecs and the options Hash
Source
# File lib/git/repository/stashing.rb, line 587 def split_stash_and_opts(stash, trailing) return [nil, stash] if stash.is_a?(Hash) && trailing.empty? [stash, trailing] end
Separate the stash operand from a positional options Hash
The stash-taking facade methods are declared ‘(stash = nil, opts = {})`. When the caller omits the stash and passes only options (`repo.stash_apply(index: true)`), Ruby binds the Hash to `stash`; this moves it to `opts` so both call shapes reach the command the same way.
@example Options passed without a stash
Private.split_stash_and_opts({ index: true }, {}) #=> [nil, { index: true }]
@example A stash and options
Private.split_stash_and_opts('stash@{1}', { index: true }) #=> ["stash@{1}", { index: true }]
@param stash [Git::StashInfo, String, Integer, Hash, nil] the stash
operand, or the options Hash when the stash was omitted
@param trailing [Hash] the second positional argument as bound by Ruby
@return [Array(Object, Hash)] the stash operand and the options Hash