class RJGit::Repo
Constants
- PACK_LIST
Attributes
git[RW]
jrepo[RW]
path[RW]
Public Class Methods
create(path, options = {:is_bare => false})
click to toggle source
# File lib/repo.rb, line 82 def self.create(path, options = {:is_bare => false}) options[:create] = true Repo.new(path, options) end
new(path, options = {})
click to toggle source
# File lib/repo.rb, line 43 def initialize(path, options = {}) epath = File.expand_path(path) if options[:git_dir] if (Pathname.new options[:git_dir]).absolute? gitpath = options[:git_dir] else gitpath = File.expand_path(options[:git_dir]) end else gitpath = File.join(epath, '.git') end # Default value for bare bare = false # If the repo path is new unless File.exists?(epath) # take user setting if defined bare = !! options[:is_bare] unless options[:is_bare].nil? # If the repo path exists else # scan the directory for a .git directory bare = File.exists?(gitpath) ? false : true # but allow overriding user setting bare = !! options[:is_bare] unless options[:is_bare].nil? end @path = bare ? epath : gitpath @config = RJGit::Configuration.new(File.join(@path, 'config')) repo_path = java.io.File.new(@path) @jrepo = bare ? RepositoryBuilder.new().set_bare.set_git_dir(repo_path).build() : RepositoryBuilder.new().set_git_dir(repo_path).set_work_tree(java.io.File.new(epath)).build() @jrepo.create(bare) if options[:create] @git = RubyGit.new(@jrepo) end
new_from_jgit_repo(jrepo)
click to toggle source
# File lib/repo.rb, line 91 def self.new_from_jgit_repo(jrepo) path = File.dirname(jrepo.get_directory.get_path) Repo.new(path, {:is_bare => jrepo.is_bare}) end
Public Instance Methods
add(file_pattern)
click to toggle source
# File lib/repo.rb, line 158 def add(file_pattern) @git.add(file_pattern) end
bare?()
click to toggle source
# File lib/repo.rb, line 77 def bare? @jrepo.is_bare end
Also aliased as: bare
blob(file_path, revstring=Constants::HEAD)
click to toggle source
Convenience method to retrieve a Blob
by name
# File lib/repo.rb, line 211 def blob(file_path, revstring=Constants::HEAD) Blob.find_blob(@jrepo, file_path, revstring) end
branch()
click to toggle source
# File lib/repo.rb, line 113 def branch @jrepo.get_full_branch end
branches()
click to toggle source
# File lib/repo.rb, line 117 def branches return @git.branch_list end
checkout(branch_name, options = {})
click to toggle source
# File lib/repo.rb, line 133 def checkout(branch_name, options = {}) @git.checkout(branch_name, options) end
Also aliased as: switch
clean(options = {})
click to toggle source
# File lib/repo.rb, line 170 def clean(options = {}) @git.clean(options) end
commit(message, options = {})
click to toggle source
# File lib/repo.rb, line 166 def commit(message, options = {}) @git.commit(message, options) end
commits(ref="master", limit=100)
click to toggle source
# File lib/repo.rb, line 96 def commits(ref="master", limit=100) options = { :limit => limit } Commit.find_all(@jrepo, ref, options) end
config()
click to toggle source
# File lib/repo.rb, line 109 def config @config.load end
create!()
click to toggle source
# File lib/repo.rb, line 87 def create! @jrepo.create(self.bare?) end
create_branch(name)
click to toggle source
# File lib/repo.rb, line 121 def create_branch(name) @git.create_branch(name) end
delete_branch(name)
click to toggle source
# File lib/repo.rb, line 125 def delete_branch(name) @git.delete_branch(name) end
find(sha, type = :any)
click to toggle source
# File lib/repo.rb, line 174 def find(sha, type = :any) begin oi = ObjectId.from_string(sha) walk = RevWalk.new(@jrepo) rev_object = case type when :any walk.parse_any(oi) when :tree walk.parse_tree(oi) when :blob walk.parse_any(oi) when :tag walk.parse_tag(oi) when :commit walk.parse_commit(oi) else nil end rescue Java::OrgEclipseJgitErrors::MissingObjectException, Java::JavaLang::IllegalArgumentException, Java::JavaLang::NullPointerException return nil end return nil if rev_object.nil? object_type = (type == :any || type == :blob) ? RJGit.sym_for_type(rev_object.get_type) : type return nil if type == :blob && object_type != :blob # Blobs need to be found with parse_any, so make sure that the result of this is actually a blob. return case object_type when :tree Tree.new(@jrepo, nil, nil, rev_object) when :blob mode = RJGit.get_file_mode(@jrepo, rev_object) Blob.new(@jrepo, mode, nil, rev_object) when :tag Tag.new(rev_object) when :commit Commit.new(jrepo, rev_object) end end
head()
click to toggle source
# File lib/repo.rb, line 101 def head Commit.find_head(@jrepo) end
notes(ref=Note::DEFAULT_REF)
click to toggle source
# File lib/repo.rb, line 220 def notes(ref=Note::DEFAULT_REF) @git.jgit.notes_list().set_notes_ref(ref).call().to_a.map do |jnote| Note.new(@jrepo, jnote) end end
remove(file_pattern)
click to toggle source
# File lib/repo.rb, line 162 def remove(file_pattern) @git.remove(file_pattern) end
rename_branch(old_name, new_name)
click to toggle source
# File lib/repo.rb, line 129 def rename_branch(old_name, new_name) @git.rename_branch(old_name, new_name) end
tree(file_path, revstring=Constants::HEAD)
click to toggle source
Convenience method to retrieve a Tree
by name
# File lib/repo.rb, line 216 def tree(file_path, revstring=Constants::HEAD) Tree.find_tree(@jrepo, file_path, revstring) end
update_ref(commit, force = false, ref = "refs/heads/
click to toggle source
# File lib/repo.rb, line 226 def update_ref(commit, force = false, ref = "refs/heads/#{Constants::MASTER}") ref_updater = @jrepo.updateRef(ref) ref_updater.setForceUpdate(force) ref_updater.setNewObjectId(RJGit.commit_type(commit)) ref_updater.update.to_string end
update_server_info()
click to toggle source
Update the info files required for fetching files over the dumb-HTTP protocol
# File lib/repo.rb, line 234 def update_server_info # First update the $GIT_DIR/refs/info file refs = @jrepo.get_all_refs # Note: JGit will include directories under $GIT_DIR/refs/heads that start with a '.' in its search for refs. Filter these out in LocalRefWriter? writer = LocalRefWriter.new(refs, @path) writer.write_info_refs # Now update the $GIT_OBJECT_DIRECTORY/info/packs file f = File.new(File.join(@path, PACK_LIST), "w") @jrepo.get_object_database.get_packs.each do |pack| f.write "P " + pack.get_pack_file.get_name + "\n" end f.write "\n" f.close return true end
valid?()
click to toggle source
# File lib/repo.rb, line 105 def valid? @jrepo.get_object_database.exists end