lib/method_log/commit.rb in method_log-0.0.2 vs lib/method_log/commit.rb in method_log-0.0.3
- old
+ new
@@ -15,36 +15,50 @@
def add(source_file)
oid = @repository.write(source_file.source, :blob)
@index.add(path: source_file.path, oid: oid, mode: 0100644)
end
- def apply
+ def apply(user: { email: 'test@example.com', name: 'test', time: Time.now }, message: 'commit-message')
tree = @index.write_tree(@repository)
parents = @repository.empty? ? [] : [@repository.head.target].compact
- user = { email: 'test@example.com', name: 'test', time: Time.now }
- @sha = Rugged::Commit.create(@repository, tree: tree, parents: parents, update_ref: 'HEAD', author: user, committer: user, message: 'commit-message')
+ @sha = Rugged::Commit.create(@repository, tree: tree, parents: parents, update_ref: 'HEAD', author: user, committer: user, message: message)
end
def source_files
- commit = @repository.lookup(sha)
source_files = []
commit.tree.walk_blobs do |root, blob_hash|
- path = root.empty? ? blob_hash[:name] : File.join(root, blob_hash[:name])
+ name = blob_hash[:name]
+ next unless File.extname(name) == '.rb'
+ path = root.empty? ? name : File.join(root, name)
source = @repository.lookup(blob_hash[:oid]).text
source_files << SourceFile.new(path: path, source: source)
end
source_files
end
+ def author
+ commit.author
+ end
+
+ def message
+ commit.message
+ end
+
def ==(other)
sha == other.sha
end
def hash
sha.hash
end
def to_s
sha
+ end
+
+ private
+
+ def commit
+ @commit ||= @repository.lookup(sha)
end
end
end
\ No newline at end of file