Skip to content

Commit

Permalink
Implement ApplyPatchToIndex Class (#50)
Browse files Browse the repository at this point in the history
* Implement ApplyPatchToIndex Class
  • Loading branch information
dometto committed Mar 14, 2020
1 parent 0d2e6f2 commit 34ff09a
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 122 deletions.
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://rubygems.org'

gem "mime-types", "~> 2.6.2"
gem "rake", "~> 10.4.2"
gem 'mime-types', '~> 2.6.2'
gem 'rake', '>= 12.3.3'

gem 'coveralls', require: false
gem 'coveralls', '~> 0.8.23', require: false

group :test do
gem "rspec", "~> 3.4.0"
gem "rspec-collection_matchers", "~> 1.1.2"
gem "simplecov"
gem 'rspec', '~> 3.4.0'
gem 'rspec-collection_matchers', '~> 1.1.2'
gem 'simplecov'
end
4 changes: 2 additions & 2 deletions lib/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def self.new_with_tree(repository, tree, message, actor, parents = nil)
Commit.new(repository, RevWalk.new(repository).parseCommit(new_commit))
end

def self.find_head(repository)
def self.find_head(repository, ref = Constants::HEAD)
repository = RJGit.repository_type(repository)
return nil if repository.nil?
begin
walk = RevWalk.new(repository)
objhead = repository.resolve(Constants::HEAD)
objhead = repository.resolve(ref)
return Commit.new(repository, walk.parseCommit(objhead))
rescue java.lang.NullPointerException => e
return nil
Expand Down
8 changes: 7 additions & 1 deletion lib/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module RJGit
import 'org.eclipse.jgit.api.TransportConfigCallback'
import 'org.eclipse.jgit.transport.JschConfigSessionFactory'
import 'org.eclipse.jgit.transport.SshTransport'

class PatchApplyException < StandardError; end

class RubyGit

Expand Down Expand Up @@ -289,7 +291,11 @@ def checkout(branch_name = "master", options = {})
end

def apply(input_stream)
apply_result = @jgit.apply.set_patch(input_stream).call
begin
apply_result = @jgit.apply.set_patch(input_stream).call
rescue Java::OrgEclipseJgitApiErrors::PatchApplyException
raise RJGit::PatchApplyException
end
updated_files = apply_result.get_updated_files
updated_files_parsed = []
updated_files.each do |file|
Expand Down

0 comments on commit 34ff09a

Please sign in to comment.