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.



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/git/object.rb', line 151

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



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

def author     
  check_commit
  @author
end

#author_dateObject



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

def author_date
  author.date
end

#commit?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/git/object.rb', line 223

def commit?
  true
end

#committerObject

git author



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

def committer
  check_commit
  @committer
end

#committer_dateObject Also known as: date



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

def committer_date 
  committer.date
end

#diff_parentObject



208
209
210
# File 'lib/git/object.rb', line 208

def diff_parent
  diff(parent)
end

#gtreeObject



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

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

#messageObject



163
164
165
166
# File 'lib/git/object.rb', line 163

def message
  check_commit
  @message
end

#nameObject



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

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

#parentObject



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

def parent
  parents.first
end

#parentsObject

array of all parent commits



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

def parents
  check_commit
  @parents        
end

#set_commit(data) ⇒ Object



212
213
214
215
216
217
218
219
220
221
# File 'lib/git/object.rb', line 212

def set_commit(data)
  if data['sha']
    @sha = data['sha']
  end
  @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