Class: BetweenMeals::Repo::Git
Defined Under Namespace
Classes: Cmd
Instance Attribute Summary
#bin, #repo_path
Instance Method Summary
collapse
#create, get, #head, #head_msg, #head_msg=, #initialize, #latest_revision
Instance Method Details
#changes(start_ref, end_ref) ⇒ Object
Return files changed between two revisions
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/between_meals/repo/git.rb', line 83
def changes(start_ref, end_ref)
valid_ref?(start_ref)
valid_ref?(end_ref) if end_ref
stdout = @cmd.diff(start_ref, end_ref).stdout
begin
parse_status(stdout).compact
rescue StandardError => e
@logger.error(
'Something went wrong. Please report this output.',
)
@logger.error(e)
stdout.lines.each do |line|
@logger.error(line.strip)
end
exit(1)
end
end
|
#checkout(url) ⇒ Object
77
78
79
80
|
# File 'lib/between_meals/repo/git.rb', line 77
def checkout(url)
@cmd.clone(url, @repo_path)
@repo = Rugged::Repository.new(File.expand_path(@repo_path))
end
|
#email ⇒ Object
129
130
131
|
# File 'lib/between_meals/repo/git.rb', line 129
def email
@cmd.config('user.email').stdout.strip
end
|
#exists? ⇒ Boolean
46
47
48
|
# File 'lib/between_meals/repo/git.rb', line 46
def exists?
!@repo.nil?
end
|
#files ⇒ Object
107
108
109
|
# File 'lib/between_meals/repo/git.rb', line 107
def files
@repo.index.map { |x| { :path => x[:path], :status => :created } }
end
|
#head_parents ⇒ Object
71
72
73
74
75
|
# File 'lib/between_meals/repo/git.rb', line 71
def head_parents
@repo.head.target.parents.map do |x|
{ :rev => x.tree.oid, :time => x.time }
end
end
|
#head_rev ⇒ Object
50
51
52
|
# File 'lib/between_meals/repo/git.rb', line 50
def head_rev
@repo.head.target.oid
end
|
#last_author ⇒ Object
67
68
69
|
# File 'lib/between_meals/repo/git.rb', line 67
def last_author
@repo.head.target.to_hash[:author]
end
|
#last_msg ⇒ Object
54
55
56
|
# File 'lib/between_meals/repo/git.rb', line 54
def last_msg
@repo.head.target.message
end
|
#last_msg=(msg) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/between_meals/repo/git.rb', line 58
def last_msg=(msg)
@repo.head.target.amend(
{
:message => msg,
:update_ref => 'HEAD',
},
)
end
|
#name ⇒ Object
125
126
127
|
# File 'lib/between_meals/repo/git.rb', line 125
def name
@cmd.config('user.name').stdout.strip
end
|
#setup ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/between_meals/repo/git.rb', line 28
def setup
if File.exists?(File.expand_path(@repo_path))
begin
@repo = Rugged::Repository.new(File.expand_path(@repo_path))
rescue StandardError
@repo = nil
end
else
@repo = nil
end
@bin = 'git'
@cmd = BetweenMeals::Repo::Git::Cmd.new(
:bin => @bin,
:cwd => @repo_path,
:logger => @logger,
)
end
|
#status ⇒ Object
121
122
123
|
# File 'lib/between_meals/repo/git.rb', line 121
def status
@cmd.status.stdout.strip
end
|
#update ⇒ Object
102
103
104
|
# File 'lib/between_meals/repo/git.rb', line 102
def update
@cmd.pull.stdout
end
|
#upstream?(rev, master = 'remotes/trunk') ⇒ Boolean
111
112
113
114
115
116
117
118
119
|
# File 'lib/between_meals/repo/git.rb', line 111
def upstream?(rev, master = 'remotes/trunk')
if @cmd.merge_base(rev, master).stdout.strip == rev
return true
end
return false
rescue StandardError
return false
end
|
#valid_ref?(ref) ⇒ Boolean
133
134
135
136
137
|
# File 'lib/between_meals/repo/git.rb', line 133
def valid_ref?(ref)
unless @repo.exists?(ref)
fail Changeset::ReferenceError
end
end
|