Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Tree#find_blob #25

Merged
merged 5 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gollum-rjgit_adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.summary = %q{Adapter for Gollum to use RJGit at the backend.}
s.description = %q{Adapter for Gollum to use RJGit at the backend.}

s.add_runtime_dependency "rjgit", "~> 6.1"
s.add_runtime_dependency "rjgit", "~> 6.5"
s.add_development_dependency "rspec", "3.4.0"

s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
Expand Down
12 changes: 10 additions & 2 deletions lib/rjgit_adapter/git_layer_rjgit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
def lstree(sha, options={})
entries = RJGit::Porcelain.ls_tree(@repo.jrepo, nil, @repo.find(sha, :tree), {:recursive => options[:recursive]})
entries.map! do |entry|
entry[:mode] = entry[:mode].to_s(8)
entry[:mode] = entry[:mode]
entry[:sha] = entry[:id]
entry
end
Expand Down Expand Up @@ -478,13 +478,21 @@ def id
end

def /(file)
@tree.send(:/, file)
obj = @tree.send(:/, file)
return nil if obj.nil?
obj.is_a?(RJGit::Tree) ? Gollum::Git::Tree.new(obj) : Gollum::Git::Blob.new(obj)
end

def blobs
return Array.new if @tree == {}
@tree.blobs.map{|blob| Gollum::Git::Blob.new(blob) }
end

def find_blob(&block)
return nil unless block_given?
blob = @tree.find_blob {|blob| yield blob[:name] }
blob ? Gollum::Git::Blob.new(blob) : nil
end
end

class NoSuchShaFound < StandardError
Expand Down