Module: Git::Parsers::LsRemote Private
- Defined in:
- lib/git/parsers/ls_remote.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.
Parser for git ls-remote command output
Class Method Summary collapse
-
.parse_default_branch(output) ⇒ String
private
Parse
git ls-remote --symref <repo> HEADoutput into a branch name. -
.parse_line(line) ⇒ Array(String, String|nil, Hash)
private
Parse a single
git ls-remoteoutput line. -
.parse_output(lines) ⇒ Hash{String => Hash}
private
Parse
git ls-remotestdout lines into a structured Hash.
Class Method Details
.parse_default_branch(output) ⇒ 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.
Parse git ls-remote --symref <repo> HEAD output into a branch name
68 69 70 71 72 73 74 75 76 |
# File 'lib/git/parsers/ls_remote.rb', line 68 def parse_default_branch(output) match_data = output.match(%r{^ref: refs/remotes/[^/]+/(?<default_branch>[^\t]+)\t}) return match_data[:default_branch] if match_data match_data = output.match(%r{^ref: refs/heads/(?<default_branch>[^\t]+)\tHEAD$}) return match_data[:default_branch] if match_data raise Git::UnexpectedResultError, 'Unable to determine the default branch' end |
.parse_line(line) ⇒ Array(String, String|nil, Hash)
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.
Parse a single git ls-remote output line
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/git/parsers/ls_remote.rb', line 44 def parse_line(line) unless line.include?("\t") && line.match?(/\A[0-9a-f]{4,}\t/) raise Git::UnexpectedResultError, "Unexpected ls-remote output line: #{line.inspect}" end sha, info = line.split("\t", 2) ref, type, name = info.split('/', 3) type ||= 'head' type = 'branches' if type == 'heads' value = { ref: ref, sha: sha } [type, name, value] end |
.parse_output(lines) ⇒ Hash{String => Hash}
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.
Parse git ls-remote stdout lines into a structured Hash
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git/parsers/ls_remote.rb', line 24 def parse_output(lines) lines.each_with_object(Hash.new { |h, k| h[k] = {} }) do |line, hsh| type, name, value = parse_line(line) if name hsh[type][name] = value else hsh[type].update(value) end end end |