class Repository
Attributes
ctx[RW]
git_dir[RW]
path[RW]
remote_name[RW]
Public Class Methods
clone(url, dest, name = 'origin')
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 89 def self.clone(url, dest, name = 'origin') git('clone', '-o', name, url, dest) Repository.new dest end
init(dir, *args)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 94 def self.init(dir, *args) ctx = [ "--git-dir=#{File.join(dir, '.git')}", "--work-tree=#{dir}", ] command = ['init'] + args git(*(ctx + command)) Repository.new dir end
new(path)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 14 def initialize(path) path = File.expand_path(path) git_dir = File.join(path, '.git') if not File.directory? git_dir terminate "#{path} is not a git repository." end self.git_dir = git_dir self.path = path self.ctx = [ "--git-dir=#{File.expand_path(git_dir)}", "--work-tree=#{File.expand_path(path)}" ] end
Public Instance Methods
branch?(branch, remote = nil)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 74 def branch?(branch, remote = nil) if remote != nil ref = "refs/remotes/#{remote}/#{branch}" else ref = (branch.include? "refs/heads/") ? branch : "refs/heads/#{branch}" end begin cmd('show-ref', '--verify', '--quiet', ref) rescue return false end return true end
cmd(*args)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 43 def cmd(*args) self.class.git(*(self.ctx + args)) end
config(local, *args)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 47 def config(local, *args) return nil if args.empty? command = ["config"] command.push "--local" if local command += args cmd(*(self.ctx + command)) end
fetch(remote)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 31 def fetch(remote) self.cmd("fetch", "--quiet", remote) end
head()
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 57 def head begin cmd("rev-parse", "--quiet", "--abbrev-ref", "--verify", "HEAD") rescue return '' end end
ref?(ref)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 65 def ref?(ref) begin cmd('show-ref', '--tags', '--heads', ref) rescue return false end return true end
remoteUrl(name)
click to toggle source
# File lib/git_bpf/lib/repository.rb, line 35 def remoteUrl(name) begin config(false, "--get", "remote.#{name}.url").chomp rescue terminate "No remote named '#{name}' in repository: #{self.path}." end end