Class: Git::Object::Commit

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

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.



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/git/object.rb', line 158

def initialize(base, sha, init = nil)
  super(base, sha)
  @tree = nil
  @parents = nil
  @author = nil
  @committer = nil
  @message = nil
  if init
    set_commit(init)
  end
end

Instance Method Details

#authorObject

git author



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

def author     
  check_commit
  @author
end

#author_dateObject



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

def author_date
  author.date
end

#commit?Boolean

Returns:

  • (Boolean)


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

def commit?
  true
end

#committerObject

git author



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

def committer
  check_commit
  @committer
end

#committer_dateObject Also known as: date



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

def committer_date 
  committer.date
end

#diff_parentObject



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

def diff_parent
  diff(parent)
end

#gtreeObject



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

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

#messageObject



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

def message
  check_commit
  @message
end

#nameObject



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

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

#parentObject



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

def parent
  parents.first
end

#parentsObject

array of all parent commits



189
190
191
192
# File 'lib/git/object.rb', line 189

def parents
  check_commit
  @parents        
end

#set_commit(data) ⇒ Object



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

def set_commit(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