Class: RJGit::RubyGit
- Inherits:
-
Object
- Object
- RJGit::RubyGit
- Defined in:
- lib/git.rb
Constant Summary collapse
- RESET_MODES =
["HARD", "SOFT", "KEEP", "MERGE", "MIXED"]
Instance Attribute Summary collapse
-
#jgit ⇒ Object
Returns the value of attribute jgit.
-
#jrepo ⇒ Object
Returns the value of attribute jrepo.
Class Method Summary collapse
Instance Method Summary collapse
- #add(file_pattern) ⇒ Object
- #apply(input_stream) ⇒ Object
- #apply_file(patch_file) ⇒ Object
- #apply_patch(patch_content) ⇒ Object
- #branch_list ⇒ Object
- #checkout(branch_name, options = {}) ⇒ Object
- #clean(options = {}) ⇒ Object
- #clone(remote, local, options = {}) ⇒ Object
- #commit(message) ⇒ Object
- #create_branch(name) ⇒ Object
- #delete_branch(name) ⇒ Object
-
#initialize(repository) ⇒ RubyGit
constructor
A new instance of RubyGit.
- #log ⇒ Object
- #merge(commit) ⇒ Object
- #pull(options = {}) ⇒ Object
- #push(remote, refs = [], options = {}) ⇒ Object
- #push_all(remote, options = {}) ⇒ Object
- #remove(file_pattern) ⇒ Object
- #rename_branch(old_name, new_name) ⇒ Object
- #reset(ref, mode = "HARD", paths = nil) ⇒ Object
- #resolve_tag(tagref) ⇒ Object
- #revert(commits) ⇒ Object
- #status ⇒ Object
- #tag(name, message = "", commit_or_revision = nil, actor = nil, force = false) ⇒ Object
Constructor Details
#initialize(repository) ⇒ RubyGit
Returns a new instance of RubyGit.
21 22 23 24 |
# File 'lib/git.rb', line 21 def initialize(repository) @jrepo = RJGit.repository_type(repository) @jgit = Git.new(@jrepo) end |
Instance Attribute Details
#jgit ⇒ Object
Returns the value of attribute jgit.
14 15 16 |
# File 'lib/git.rb', line 14 def jgit @jgit end |
#jrepo ⇒ Object
Returns the value of attribute jrepo.
15 16 17 |
# File 'lib/git.rb', line 15 def jrepo @jrepo end |
Class Method Details
.clone(remote, local, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/git.rb', line 52 def self.clone(remote, local, = {}) clone_command = Git.clone_repository clone_command.setURI(remote) clone_command.set_directory(java.io.File.new(local)) clone_command.(true) if [:is_bare] if [:branch] if [:branch] == :all clone_command.set_clone_all_branches(true) else clone_command.set_branch([:branch]) end end if [:username] clone_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new([:username], [:password])) end clone_command.call Repo.new(local) end |
Instance Method Details
#add(file_pattern) ⇒ Object
71 72 73 |
# File 'lib/git.rb', line 71 def add(file_pattern) @jgit.add.add_filepattern(file_pattern).call end |
#apply(input_stream) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/git.rb', line 140 def apply(input_stream) apply_result = @jgit.apply.set_patch(input_stream).call 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) ⇒ Object
155 156 157 158 |
# File 'lib/git.rb', line 155 def apply_file(patch_file) input_stream = FileInputStream.new(patch_file) apply(input_stream) end |
#apply_patch(patch_content) ⇒ Object
150 151 152 153 |
# File 'lib/git.rb', line 150 def apply_patch(patch_content) input_stream = ByteArrayInputStream.new(patch_content.to_java_bytes) apply(input_stream) end |
#branch_list ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/git.rb', line 35 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, options = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/git.rb', line 124 def checkout(branch_name, = {}) checkout_command = @jgit.checkout.set_name(branch_name) checkout_command.set_create_branch(true) if [:create] checkout_command.set_force(true) if [: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 = {}) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/git.rb', line 160 def clean( = {}) clean_command = @jgit.clean clean_command.set_dry_run(true) if [:dryrun] clean_command.set_paths(java.util.Arrays.asList([:paths])) if [:paths] clean_command.call end |
#clone(remote, local, options = {}) ⇒ Object
48 49 50 |
# File 'lib/git.rb', line 48 def clone(remote, local, = {}) RubyGit.clone(remote, local, ) end |
#commit(message) ⇒ Object
44 45 46 |
# File 'lib/git.rb', line 44 def commit() Commit.new(jrepo, @jgit.commit.().call) end |
#create_branch(name) ⇒ Object
112 113 114 |
# File 'lib/git.rb', line 112 def create_branch(name) @jgit.branch_create.setName(name).call end |
#delete_branch(name) ⇒ Object
116 117 118 |
# File 'lib/git.rb', line 116 def delete_branch(name) @jgit.branch_delete.set_branch_names(name).call end |
#log ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/git.rb', line 26 def log logs = @jgit.log commits = Array.new logs.call.each do |jcommit| commits << Commit.new(jrepo, jcommit) end commits end |
#merge(commit) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/git.rb', line 79 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(options = {}) ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/git.rb', line 218 def pull( = {}) pull_command = @jgit.pull pull_command.set_dry_run(true) if [:dryrun] pull_command.set_rebase([:rebase]) if [:rebase] if [:username] pull_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new([:username], [:password])) end pull_command.call end |
#push(remote, refs = [], options = {}) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/git.rb', line 204 def push(remote, refs = [], = {}) if(refs.size > 0) refs.map!{|ref| RefSpec.new(ref)} push_command = @jgit.push push_command.set_dry_run(true) if [:dryrun] push_command.set_remote(remote) push_command.set_ref_specs(refs) if [:username] push_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new([:username], [:password])) end push_command.call end end |
#push_all(remote, options = {}) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/git.rb', line 192 def push_all(remote, = {}) push_command = @jgit.push push_command.set_dry_run(true) if [:dryrun] push_command.set_remote(remote) push_command.set_push_all push_command. if [:username] push_command.set_credentials_provider(UsernamePasswordCredentialsProvider.new([:username], [:password])) end push_command.call end |
#remove(file_pattern) ⇒ Object
75 76 77 |
# File 'lib/git.rb', line 75 def remove(file_pattern) @jgit.rm.add_filepattern(file_pattern).call end |
#rename_branch(old_name, new_name) ⇒ Object
120 121 122 |
# File 'lib/git.rb', line 120 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) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/git.rb', line 167 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) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/git.rb', line 103 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) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/git.rb', line 180 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 ⇒ Object
188 189 190 |
# File 'lib/git.rb', line 188 def status @jgit.status.call end |
#tag(name, message = "", commit_or_revision = nil, actor = nil, force = false) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/git.rb', line 90 def tag(name, = "", 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.() 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 |