Class: Repository
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
execute, expand_path, git, options, page, run, sh, trace
#branchExists?, #context, #promptYN, #refExists?, #terminate
Constructor Details
Returns a new instance of Repository.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# 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
|
Instance Attribute Details
#ctx ⇒ Object
Returns the value of attribute ctx.
12
13
14
|
# File 'lib/git_bpf/lib/repository.rb', line 12
def ctx
@ctx
end
|
#git_dir ⇒ Object
Returns the value of attribute git_dir.
12
13
14
|
# File 'lib/git_bpf/lib/repository.rb', line 12
def git_dir
@git_dir
end
|
#path ⇒ Object
Returns the value of attribute path.
12
13
14
|
# File 'lib/git_bpf/lib/repository.rb', line 12
def path
@path
end
|
#remote_name ⇒ Object
Returns the value of attribute remote_name.
12
13
14
|
# File 'lib/git_bpf/lib/repository.rb', line 12
def remote_name
@remote_name
end
|
Class Method Details
.clone(url, dest, name = 'origin') ⇒ Object
89
90
91
92
|
# 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) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# 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
|
Instance Method Details
#branch?(branch, remote = nil) ⇒ Boolean
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# 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) ⇒ Object
43
44
45
|
# File 'lib/git_bpf/lib/repository.rb', line 43
def cmd(*args)
self.class.git(*(self.ctx + args))
end
|
#config(local, *args) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# 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) ⇒ Object
31
32
33
|
# File 'lib/git_bpf/lib/repository.rb', line 31
def fetch(remote)
self.cmd("fetch", "--quiet", remote)
end
|
#head ⇒ Object
57
58
59
60
61
62
63
|
# 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) ⇒ Boolean
65
66
67
68
69
70
71
72
|
# 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) ⇒ Object
35
36
37
38
39
40
41
|
# 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
|