class Graal::Backend::Exe::Git
Constants
- COMMIT_SHOW_FORMAT
Public Class Methods
new(repository)
click to toggle source
# File lib/graal/exe/git.rb, line 31 def initialize(repository) @repository = repository end
Public Instance Methods
blob_contents(gitid)
click to toggle source
# File lib/graal/exe/git.rb, line 96 def blob_contents(gitid) run('cat-file', '-p', gitid).output end
child(gitid, fullpath)
click to toggle source
# File lib/graal/exe/git.rb, line 80 def child(gitid, fullpath) result = run('ls-tree', gitid, fullpath) return result.output.split(" ")[1..2] end
children(gitid, path, filter = nil)
click to toggle source
# File lib/graal/exe/git.rb, line 85 def children(gitid, path, filter = nil) result = run('ls-tree', gitid, path) children = [] result.output.split("\n").each do |line| splitted = line.split(" ") next unless filter.nil? or splitted[1] == filter children << [splitted[1], splitted[3], splitted[2]] end children end
commit_info(revision)
click to toggle source
# File lib/graal/exe/git.rb, line 67 def commit_info(revision) result = run('show', '--quiet', COMMIT_SHOW_FORMAT, revision) ary = result.output.split("\n") ary[8] = ary[8..-1] * "\n" if ary.size > 9 ary end
gitid_for(revision, path)
click to toggle source
# File lib/graal/exe/git.rb, line 58 def gitid_for(revision, path) if path.empty? result = run('rev-parse', revision).output.chomp else result = run('ls-tree', revision, path) result.output.split(' ')[2] end end
heads()
click to toggle source
# File lib/graal/exe/git.rb, line 48 def heads result = run('branch', '--no-color', '--no-column') result.output.gsub(/^[ *]*/, '').split("\n") end
log(revision, path, raw_opts = {})
click to toggle source
# File lib/graal/exe/git.rb, line 74 def log(revision, path, raw_opts = {}) opts = parse_opts(raw_opts) result = run_with_pathspec('rev-list', *opts, revision, path) result.output.split("\n") end
run(cmd, *args)
click to toggle source
# File lib/graal/exe/git.rb, line 35 def run(cmd, *args) do_run(['git', cmd, *args]) end
run_with_pathspec(cmd, *args, pathspec)
click to toggle source
# File lib/graal/exe/git.rb, line 39 def run_with_pathspec(cmd, *args, pathspec) command_line = ['git', cmd, *args] unless pathspec.nil? or pathspec.empty? command_line << '--' command_line << pathspec end do_run(command_line) end
Private Instance Methods
do_run(command_line)
click to toggle source
# File lib/graal/exe/git.rb, line 108 def do_run(command_line) process = ChildProcess.build(*command_line) process.cwd = @repository out, process.io.stdout, err, process.io.stderr = *IO.pipe, *IO.pipe process.start process.wait process.io.stdout.close process.io.stderr.close Result.new(process.exit_code, out, err) end
git_directory()
click to toggle source
# File lib/graal/exe/git_ruby.rb, line 15 def git_directory live = File.join(@repository, '.git') return live if File.exists? live return @repository end
parse_opts(opts)
click to toggle source
# File lib/graal/exe/git.rb, line 102 def parse_opts(opts) opts.each_with_object([]) do |opt, array| array << '--' + (opt[1] == true ? opt[0] : opt * '=') end end
refs(type)
click to toggle source
# File lib/graal/exe/git_ruby.rb, line 21 def refs(type) refs = [] git_dir = git_directory refs_dir = File.join(git_dir, 'refs', type) if File.exists? refs_dir Dir.chdir refs_dir do Dir['*'].each { |ref| refs << ref if File.file?(ref) } end end packed = File.join(git_dir, 'packed-refs') if File.exists? packed pattern = %r{ refs/#{type}/(.+)$} File.read(packed).scan(pattern).each { |m| refs << m.first } end refs end