Class: Git::Object::Commit

Inherits:
AbstractObject show all
Defined in:
lib/git/object.rb

Overview

A Git commit object

Instance Attribute Summary

Attributes inherited from AbstractObject

#mode, #objectish, #size, #type

Instance Method Summary collapse

Methods inherited from AbstractObject

#archive, #blob?, #contents, #contents_array, #diff, #grep, #log, #sha, #tag?, #to_s, #tree?

Constructor Details

#initialize(base, sha, init = nil) ⇒ Commit

Returns a new instance of Commit.



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/git/object.rb', line 154

def initialize(base, sha, init = nil)
  super(base, sha)
  @tree = nil
  @parents = nil
  @author = nil
  @committer = nil
  @message = nil
  return unless init

  from_data(init)
end

Instance Method Details

#author

git author



191
192
193
194
# File 'lib/git/object.rb', line 191

def author
  check_commit
  @author
end

#author_date



196
197
198
# File 'lib/git/object.rb', line 196

def author_date
  author.date
end

#commit?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'lib/git/object.rb', line 229

def commit?
  true
end

#committer

git author



201
202
203
204
# File 'lib/git/object.rb', line 201

def committer
  check_commit
  @committer
end

#committer_date Also known as: date



206
207
208
# File 'lib/git/object.rb', line 206

def committer_date
  committer.date
end

#diff_parent



211
212
213
# File 'lib/git/object.rb', line 211

def diff_parent
  diff(parent)
end

#from_data(data)



220
221
222
223
224
225
226
227
# File 'lib/git/object.rb', line 220

def from_data(data)
  @sha ||= data['sha']
  @committer = Git::Author.new(data['committer'])
  @author = Git::Author.new(data['author'])
  @tree = Git::Object::Tree.new(@base, data['tree'])
  @parents = data['parent'].map { |sha| Git::Object::Commit.new(@base, sha) }
  @message = data['message'].chomp
end

#gtree



175
176
177
178
# File 'lib/git/object.rb', line 175

def gtree
  check_commit
  Tree.new(@base, @tree)
end

#message



166
167
168
169
# File 'lib/git/object.rb', line 166

def message
  check_commit
  @message
end

#name



171
172
173
# File 'lib/git/object.rb', line 171

def name
  @base.lib.name_rev(sha)
end

#parent



180
181
182
# File 'lib/git/object.rb', line 180

def parent
  parents.first
end

#parents

array of all parent commits



185
186
187
188
# File 'lib/git/object.rb', line 185

def parents
  check_commit
  @parents
end

#set_commit(data)

rubocop:disable Naming/AccessorMethodName



215
216
217
218
# File 'lib/git/object.rb', line 215

def set_commit(data) # rubocop:disable Naming/AccessorMethodName
  Git.deprecation('Git::Object::Commit#set_commit is deprecated. Use #from_data instead.')
  from_data(data)
end