Class: RJGit::RubyGit
- Inherits:
-
Object
- Object
- RJGit::RubyGit
- Defined in:
- lib/git.rb
Defined Under Namespace
Classes: RJGitSSHConfigCallback
Constant Summary collapse
- RESET_MODES =
["HARD", "SOFT", "KEEP", "MERGE", "MIXED"]
- SSH_TRANSPORTS =
["ssh"]
- HTTP_TRANSPORTS =
["http", "https"]
- FILE_TRANSPORTS =
["file"]
- VALID_TRANSPORTS =
SSH_TRANSPORTS + HTTP_TRANSPORTS + FILE_TRANSPORTS
Instance Attribute Summary collapse
-
#jgit ⇒ Object
Returns the value of attribute jgit.
-
#jrepo ⇒ Object
Returns the value of attribute jrepo.
Class Method Summary collapse
- .clone(remote, local, options = {}) ⇒ Object
- .set_command_transport(command, remote, options = {}) ⇒ Object
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 = "master", options = {}) ⇒ Object
- #clean(options = {}) ⇒ Object
- #clone(remote, local, options = {}) ⇒ Object
- #commit(message, options = {}) ⇒ Object
- #create_branch(name) ⇒ Object
- #delete_branch(name) ⇒ Object
- #fetch(remote = nil, options = {}) ⇒ Object
-
#initialize(repository) ⇒ RubyGit
constructor
A new instance of RubyGit.
- #log(path = nil, revstring = Constants::HEAD, options = {}) ⇒ Object
- #logs(refs, options = {}) ⇒ Object
- #merge(commit) ⇒ Object
- #pull(remote = nil, remote_ref = nil, options = {}) ⇒ Object
- #push(remote = nil, 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.
36 37 38 39 |
# File 'lib/git.rb', line 36 def initialize(repository) @jrepo = RJGit.repository_type(repository) @jgit = Git.new(@jrepo) end |
Instance Attribute Details
#jgit ⇒ Object
Returns the value of attribute jgit.
25 26 27 |
# File 'lib/git.rb', line 25 def jgit @jgit end |
#jrepo ⇒ Object
Returns the value of attribute jrepo.
26 27 28 |
# File 'lib/git.rb', line 26 def jrepo @jrepo end |
Class Method Details
.clone(remote, local, options = {}) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/git.rb', line 193 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 set_command_transport(clone_command, remote, ) clone_command.call Repo.new(local) end |
.set_command_transport(command, remote, options = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/git.rb', line 174 def self.set_command_transport(command, remote, = {}) 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) || ([:transport_protocol] == :ssh) || [:private_key_file] command.set_transport_config_callback(RJGitSSHConfigCallback.new()) elsif (HTTP_TRANSPORTS.include? transport_protocol.to_s) || [:username] [:password] = '' unless [:password] command.set_credentials_provider(UsernamePasswordCredentialsProvider.new([:username], [:password])) end end |
Instance Method Details
#add(file_pattern) ⇒ Object
211 212 213 |
# File 'lib/git.rb', line 211 def add(file_pattern) @jgit.add.add_filepattern(file_pattern).call end |
#apply(input_stream) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 |
# 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) ⇒ Object
306 307 308 309 |
# 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) ⇒ Object
301 302 303 304 |
# 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 ⇒ Object
107 108 109 110 111 112 113 114 |
# 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 = {}) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/git.rb', line 264 def checkout(branch_name = "master", = {}) checkout_command = @jgit.checkout.set_name(branch_name) # call :setStartPoint directly to avoid ambiguity warning if [:commit].is_a?(org.eclipse.jgit.revwalk.RevCommit) checkout_command.java_send :setStartPoint, [org.eclipse.jgit.revwalk.RevCommit], [:commit] else checkout_command.java_send :setStartPoint, [java.lang.String], [:commit] end [:paths].each {|path| checkout_command.add_path(path)} if [:paths] 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
311 312 313 314 315 316 |
# File 'lib/git.rb', line 311 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
128 129 130 |
# File 'lib/git.rb', line 128 def clone(remote, local, = {}) RubyGit.clone(remote, local, ) end |
#commit(message, options = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/git.rb', line 116 def commit(, = {}) commit_cmd = @jgit.commit.() commit_cmd.set_all([:all]) unless [:all].nil? commit_cmd.set_amend([:amend]) unless [:amend].nil? commit_cmd.([:author].person_ident) unless [:author].nil? commit_cmd.set_committer([:committer].person_ident) unless [:committer].nil? commit_cmd.set_insert_change_id([:insert_change_id]) unless [:insert_change_id].nil? [:only_paths].each {|path| commit_cmd.set_only(path)} unless [:only_paths].nil? commit_cmd.set_reflog_comment([:reflog_comment]) unless [:reflog_comment].nil? Commit.new(jrepo, commit_cmd.call) end |
#create_branch(name) ⇒ Object
252 253 254 |
# File 'lib/git.rb', line 252 def create_branch(name) @jgit.branch_create.setName(name).call end |
#delete_branch(name) ⇒ Object
256 257 258 |
# File 'lib/git.rb', line 256 def delete_branch(name) @jgit.branch_delete.set_branch_names(name).call end |
#fetch(remote = nil, options = {}) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/git.rb', line 378 def fetch(remote = nil, = {}) fetch_command = @jgit.fetch fetch_command.set_dry_run(true) if [:dryrun] fetch_command.set_thin(true) if [:thin] fetch_command.set_check_fetched_objects(true) if [:check_fetched_objects] fetch_command.set_remove_deleted_refs(true) if [:remove_deleted_refs] fetch_command.set_remote(remote) if remote fetch_command.set_ref_specs([:refspecs]) if [:refspecs] self.class.set_command_transport(fetch_command, remote, ) fetch_command.call end |
#log(path = nil, revstring = Constants::HEAD, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/git.rb', line 49 def log(path = nil, revstring = Constants::HEAD, = {}) ref = jrepo.resolve(revstring) return [] unless ref jcommits = Array.new logs = @jgit.log logs.add(ref) if path && [: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([:max_count]) if [:max_count] logs.setSkip([:skip]) if [:skip] if ([:since] && [:until]) revwalk = RevWalk.new(jrepo) since_commit = revwalk.parseCommit(jrepo.resolve([:since])) until_commit = revwalk.parseCommit(jrepo.resolve([:until])) logs.addRange(since_commit, until_commit) end if [:not] revwalk = RevWalk.new(jrepo) [:not].each do |ref| logs.not(revwalk.parseCommit(jrepo.resolve(ref))) end end if [:follow] && [: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 && [:follow] && [: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 = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/git.rb', line 41 def logs(refs, = {}) logs = [] refs.each do |ref| logs << log(nil, ref, ) end logs end |
#merge(commit) ⇒ Object
219 220 221 222 223 224 225 226 227 228 |
# 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 = {}) ⇒ Object
368 369 370 371 372 373 374 375 376 |
# File 'lib/git.rb', line 368 def pull(remote = nil, remote_ref = nil, = {}) pull_command = @jgit.pull pull_command.set_dry_run(true) if [:dryrun] pull_command.set_rebase([:rebase]) if [: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, ) pull_command.call end |
#push(remote = nil, refs = [], options = {}) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/git.rb', line 355 def push(remote = nil, refs = [], = {}) push_command = @jgit.push push_command.set_dry_run(true) if [:dryrun] push_command.set_force(true) if [: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, ) push_command.call end |
#push_all(remote, options = {}) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/git.rb', line 343 def push_all(remote, = {}) push_command = @jgit.push push_command.set_dry_run(true) if [:dryrun] push_command.set_force(true) if [:force] push_command.set_remote(remote) push_command.set_push_all push_command. self.class.set_command_transport(push_command, remote, ) push_command.call end |
#remove(file_pattern) ⇒ Object
215 216 217 |
# File 'lib/git.rb', line 215 def remove(file_pattern) @jgit.rm.add_filepattern(file_pattern).call end |
#rename_branch(old_name, new_name) ⇒ Object
260 261 262 |
# 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) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 |
# 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) ⇒ Object
243 244 245 246 247 248 249 250 |
# 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) ⇒ Object
331 332 333 334 335 336 337 |
# 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 ⇒ Object
339 340 341 |
# File 'lib/git.rb', line 339 def status @jgit.status.call end |
#tag(name, message = "", commit_or_revision = nil, actor = nil, force = false) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/git.rb', line 230 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 |