From 27f947fd660c7b64a262323c1588c38ecb2d2d61 Mon Sep 17 00:00:00 2001 From: Ryo Suzuki Date: Sat, 1 Jun 2013 23:28:05 +0900 Subject: [PATCH] get blob path (eg. @blob.path = 'lib/grit/blob.rb' --- lib/grit/blob.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/grit/blob.rb b/lib/grit/blob.rb index 9593d562..e9c0c467 100644 --- a/lib/grit/blob.rb +++ b/lib/grit/blob.rb @@ -29,6 +29,22 @@ def create_initialize(repo, atts) self end + # The repo object of this blob + # + # Returning Grit::Repo + def repo + @repo + end + + # The path of this blob ( eg. lib/grit/blob.rb ) + # +treeish+ is the Commit + # + # Returns String + def path(treeish = 'master') + revs = @repo.git.native(:ls_tree, {:r => true}, treeish, "| grep #{@id}") + path = revs.split("\n").first.to_s.split("\t").last + end + # The size of this blob in bytes # # Returns Integer @@ -123,4 +139,4 @@ def <=>(other) end end # Blob -end # Grit \ No newline at end of file +end # Grit