class RJGit::RubyGit
Constants
- FILE_TRANSPORTS
- HTTP_TRANSPORTS
- RESET_MODES
- SSH_TRANSPORTS
- VALID_TRANSPORTS
Attributes
jgit[RW]
jrepo[RW]
Public Class Methods
clone(remote, local, options = {})
click to toggle source
# File lib/git.rb, line 193 def self.clone(remote, local, options = {}) clone_command = Git.clone_repository clone_command.setURI(remote) clone_command.set_directory(java.io.File.new(local)) clone_command.set_bare(true) if options[:is_bare] if options[:branch] if options[:branch] == :all clone_command.set_clone_all_branches(true) else clone_command.set_branch(options[:branch]) end end set_command_transport(clone_command, remote, options) clone_command.call Repo.new(local) end
new(repository)
click to toggle source
# File lib/git.rb, line 36 def initialize(repository) @jrepo = RJGit.repository_type(repository) @jgit = Git.new(@jrepo) end
set_command_transport(command, remote, options = {})
click to toggle source
# File lib/git.rb, line 174 def self.set_command_transport(command, remote, options = {}) uri = nil begin uri = URI.parse(remote) if remote rescue URI::InvalidURIError end if uri && (VALID_TRANSPORTS.include? uri.scheme) transport_protocol = uri.scheme end if (SSH_TRANSPORTS.include? transport_protocol.to_s) || (options[:transport_protocol] == :ssh) || options[:private_key_file] command.set_transport_config_callback(RJGitSSHConfigCallback.new(options)) elsif (HTTP_TRANSPORTS.include? transport_protocol.to_s) || options[:username] options[:password] = '' unless options[:password] command.set_credentials_provider(UsernamePasswordCredentialsProvider.new(options[:username], options[:password])) end end
Public Instance Methods
add(file_pattern)
click to toggle source
# File lib/git.rb, line 211 def add(file_pattern) @jgit.add.add_filepattern(file_pattern).call end
apply(input_stream)
click to toggle source
# File lib/git.rb, line 287 def apply(input_stream) 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| updated_files_parsed << file.get_absolute_path end updated_files_parsed end
apply_file(patch_file)
click to toggle source
# File lib/git.rb, line 306 def apply_file(patch_file) input_stream = FileInputStream.new(patch_file) apply(input_stream) end
apply_patch(patch_content)
click to toggle source
# File lib/git.rb, line 301 def apply_patch(patch_content) input_stream = ByteArrayInputStream.new(patch_content.to_java_bytes) apply(input_stream) end
branch_list()
click to toggle source
# File lib/git.rb, line 107 def branch_list branch = @jgit.branch_list array = Array.new branch.call.each do |b| array << b.get_name end array end
checkout(branch_name = "master", options = {})
click to toggle source
# File lib/git.rb, line 264 def checkout(branch_name = "master", options = {}) checkout_command = @jgit.checkout.set_name(branch_name) # call :setStartPoint directly to avoid ambiguity warning if options[:commit].is_a?(org.eclipse.jgit.revwalk.RevCommit) checkout_command.java_send :setStartPoint, [org.eclipse.jgit.revwalk.RevCommit], options[:commit] else checkout_command.java_send :setStartPoint, [java.lang.String], options[:commit] end options[:paths].each {|path| checkout_command.add_path(path)} if options[:paths] checkout_command.set_create_branch(true) if options[:create] checkout_command.set_force(true) if options[:force] result = {} begin checkout_command.call result[:success] = true result[:result] = @jgit.get_repository.get_full_branch rescue Java::OrgEclipseJgitApiErrors::CheckoutConflictException => conflict result[:success] = false result[:result] = conflict.get_conflicting_paths end result end
clean(options = {})
click to toggle source
# File lib/git.rb, line 311 def clean(options = {}) clean_command = @jgit.clean clean_command.set_dry_run(true) if options[:dryrun] clean_command.set_paths(java.util.Arrays.asList(options[:paths])) if options[:paths] clean_command.call end
clone(remote, local, options = {})
click to toggle source
# File lib/git.rb, line 128 def clone(remote, local, options = {}) RubyGit.clone(remote, local, options) end
commit(message, options = {})
click to toggle source
# File lib/git.rb, line 116 def commit(message, options = {}) commit_cmd = @jgit.commit.set_message(message) commit_cmd.set_all(options[:all]) unless options[:all].nil? commit_cmd.set_amend(options[:amend]) unless options[:amend].nil? commit_cmd.set_author(options[:author].person_ident) unless options[:author].nil? commit_cmd.set_committer(options[:committer].person_ident) unless options[:committer].nil? commit_cmd.set_insert_change_id(options[:insert_change_id]) unless options[:insert_change_id].nil? options[:only_paths].each {|path| commit_cmd.set_only(path)} unless options[:only_paths].nil? commit_cmd.set_reflog_comment(options[:reflog_comment]) unless options[:reflog_comment].nil? Commit.new(jrepo, commit_cmd.call) end
create_branch(name)
click to toggle source
# File lib/git.rb, line 252 def create_branch(name) @jgit.branch_create.setName(name).call end
delete_branch(name)
click to toggle source
# File lib/git.rb, line 256 def delete_branch(name) @jgit.branch_delete.set_branch_names(name).call end
fetch(remote = nil, options = {})
click to toggle source
# File lib/git.rb, line 378 def fetch(remote = nil, options = {}) fetch_command = @jgit.fetch fetch_command.set_dry_run(true) if options[:dryrun] fetch_command.set_thin(true) if options[:thin] fetch_command.set_check_fetched_objects(true) if options[:check_fetched_objects] fetch_command.set_remove_deleted_refs(true) if options[:remove_deleted_refs] fetch_command.set_remote(remote) if remote fetch_command.set_ref_specs(options[:refspecs]) if options[:refspecs] self.class.set_command_transport(fetch_command, remote, options) fetch_command.call end
log(path = nil, revstring = Constants::HEAD, options = {})
click to toggle source
# File lib/git.rb, line 49 def log(path = nil, revstring = Constants::HEAD, options = {}) ref = jrepo.resolve(revstring) return [] unless ref jcommits = Array.new logs = @jgit.log logs.add(ref) if path && options[:follow] cfg = Configuration.new(nil) cfg.add_setting('renames', true, 'diffs', nil) follow = FollowFilter.create(path, cfg.jconfig.get(org.eclipse.jgit.diff.DiffConfig::KEY)) logs.set_rev_filter(TreeRevFilter.new(RevWalk.new(jrepo), follow)) elsif path logs.addPath(path) end logs.setMaxCount(options[:max_count]) if options[:max_count] logs.setSkip(options[:skip]) if options[:skip] if (options[:since] && options[:until]) revwalk = RevWalk.new(jrepo) since_commit = revwalk.parseCommit(jrepo.resolve(options[:since])) until_commit = revwalk.parseCommit(jrepo.resolve(options[:until])) logs.addRange(since_commit, until_commit) end if options[:not] revwalk = RevWalk.new(jrepo) options[:not].each do |ref| logs.not(revwalk.parseCommit(jrepo.resolve(ref))) end end if options[:follow] && options[:list_renames] df = DiffFormatter.new(DisabledOutputStream::INSTANCE) df.set_repository(jrepo) df.set_context(0) df.set_path_filter(follow) df.set_detect_renames(true) prev_commit = nil pathname = path end commits = logs.call.map do |jcommit| if path && options[:follow] && options[:list_renames] entries = df.scan(jcommit, prev_commit).to_a pathname = entries.empty? ? pathname : entries.last.get_old_path prev_commit = jcommit TrackingCommit.new(jrepo, jcommit, pathname) else Commit.new(jrepo, jcommit) end end commits end
logs(refs, options = {})
click to toggle source
# File lib/git.rb, line 41 def logs(refs, options = {}) logs = [] refs.each do |ref| logs << log(nil, ref, options) end logs end
merge(commit)
click to toggle source
# File lib/git.rb, line 219 def merge(commit) merge_command = @jgit.merge merge_command.include(commit.jcommit) result = merge_command.call if result.get_merge_status.to_string == 'Conflicting' return result.get_conflicts.to_hash.keys else return result end end
pull(remote = nil, remote_ref = nil, options = {})
click to toggle source
# File lib/git.rb, line 368 def pull(remote = nil, remote_ref = nil, options = {}) pull_command = @jgit.pull pull_command.set_dry_run(true) if options[:dryrun] pull_command.set_rebase(options[:rebase]) if options[:rebase] pull_command.set_remote(remote) if remote pull_command.set_remote_branch_name(remote_ref) if remote_ref self.class.set_command_transport(pull_command, remote, options) pull_command.call end
push(remote = nil, refs = [], options = {})
click to toggle source
# File lib/git.rb, line 355 def push(remote = nil, refs = [], options = {}) push_command = @jgit.push push_command.set_dry_run(true) if options[:dryrun] push_command.set_force(true) if options[:force] push_command.set_remote(remote) if remote if(refs.to_a.size > 0) refs.map!{|ref| RefSpec.new(ref)} push_command.set_ref_specs(refs) end self.class.set_command_transport(push_command, remote, options) push_command.call end
push_all(remote, options = {})
click to toggle source
# File lib/git.rb, line 343 def push_all(remote, options = {}) push_command = @jgit.push push_command.set_dry_run(true) if options[:dryrun] push_command.set_force(true) if options[:force] push_command.set_remote(remote) push_command.set_push_all push_command.set_push_tags self.class.set_command_transport(push_command, remote, options) push_command.call end
remove(file_pattern)
click to toggle source
# File lib/git.rb, line 215 def remove(file_pattern) @jgit.rm.add_filepattern(file_pattern).call end
rename_branch(old_name, new_name)
click to toggle source
# File lib/git.rb, line 260 def rename_branch(old_name, new_name) @jgit.branch_rename.set_old_name(old_name).set_new_name(new_name).call end
reset(ref, mode = "HARD", paths = nil)
click to toggle source
# File lib/git.rb, line 318 def reset(ref, mode = "HARD", paths = nil) return nil if mode != nil && !RESET_MODES.include?(mode) reset_command = @jgit.reset if paths then paths.each do |path| reset_command.addPath(path) end end reset_command.setRef(ref.id) reset_command.setMode(org.eclipse.jgit.api.ResetCommand::ResetType.valueOf(mode)) unless mode == nil reset_command.call end
resolve_tag(tagref)
click to toggle source
# File lib/git.rb, line 243 def resolve_tag(tagref) begin walk = RevWalk.new(@jrepo) walk.parse_tag(tagref.get_object_id) rescue Java::OrgEclipseJgitErrors::IncorrectObjectTypeException nil end end
revert(commits)
click to toggle source
# File lib/git.rb, line 331 def revert(commits) revert_command = @jgit.revert commits.each do |commit| revert_command.include commit.jcommit end Commit.new(jrepo, revert_command.call) end
status()
click to toggle source
# File lib/git.rb, line 339 def status @jgit.status.call end
tag(name, message = "", commit_or_revision = nil, actor = nil, force = false)
click to toggle source
# File lib/git.rb, line 230 def tag(name, message = "", commit_or_revision = nil, actor = nil, force = false) tag_command = @jgit.tag tag_command.set_name(name) tag_command.set_force_update(force) tag_command.set_message(message) tag_command.set_object_id(RJGit.commit_type(commit_or_revision)) if commit_or_revision if actor actor = RJGit.actor_type(actor) tag_command.set_tagger(actor) end tag_command.call end