Class: RJGit::Repo
- Inherits:
-
Object
- Object
- RJGit::Repo
- Defined in:
- lib/repo.rb
Constant Summary collapse
- PACK_LIST =
'objects/info/packs'
Instance Attribute Summary collapse
-
#git ⇒ Object
Returns the value of attribute git.
-
#jrepo ⇒ Object
Returns the value of attribute jrepo.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #add(file_pattern) ⇒ Object
- #bare? ⇒ Boolean (also: #bare)
-
#blob(file_path, revstring = Constants::HEAD) ⇒ Object
Convenience method to retrieve a Blob by name.
- #branch ⇒ Object
- #branches ⇒ Object
- #checkout(branch_name, options = {}) ⇒ Object (also: #switch)
- #clean(options = {}) ⇒ Object
- #commit(message, options = {}) ⇒ Object
- #commits(ref = "master", limit = 100) ⇒ Object
- #config ⇒ Object
- #create! ⇒ Object
- #create_branch(name) ⇒ Object
- #delete_branch(name) ⇒ Object
- #find(sha, type = :any) ⇒ Object
- #head ⇒ Object
-
#initialize(path, options = {}) ⇒ Repo
constructor
A new instance of Repo.
- #remove(file_pattern) ⇒ Object
- #rename_branch(old_name, new_name) ⇒ Object
- #tags(lightweight = false) ⇒ Object
-
#tree(file_path, revstring = Constants::HEAD) ⇒ Object
Convenience method to retrieve a Tree by name.
- #update_ref(commit, force = false, ref = "refs/heads/#{Constants::MASTER}") ⇒ Object
-
#update_server_info ⇒ Object
Update the info files required for fetching files over the dumb-HTTP protocol.
- #valid? ⇒ Boolean
Constructor Details
#initialize(path, options = {}) ⇒ Repo
Returns a new instance of Repo.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/repo.rb', line 43 def initialize(path, = {}) epath = File.(path) gitpath = File.join(epath, '.git') # Default value for bare = false # If the repo path is new unless File.exists?(epath) # take user setting if defined = !! [:is_bare] unless [:is_bare].nil? # If the repo path exists else # scan the directory for a .git directory = File.exists?(gitpath) ? false : true # but allow overriding user setting = !! [:is_bare] unless [:is_bare].nil? end @path = ? epath : gitpath @config = RJGit::Configuration.new(File.join(@path, 'config')) repo_path = java.io.File.new(@path) @jrepo = ? RepositoryBuilder.new()..set_git_dir(repo_path).build() : RepositoryBuilder.new().set_git_dir(repo_path).build() @jrepo.create() if [:create] @git = RubyGit.new(@jrepo) end |
Instance Attribute Details
#git ⇒ Object
Returns the value of attribute git.
35 36 37 |
# File 'lib/repo.rb', line 35 def git @git end |
#jrepo ⇒ Object
Returns the value of attribute jrepo.
36 37 38 |
# File 'lib/repo.rb', line 36 def jrepo @jrepo end |
#path ⇒ Object
Returns the value of attribute path.
37 38 39 |
# File 'lib/repo.rb', line 37 def path @path end |
Class Method Details
Instance Method Details
#add(file_pattern) ⇒ Object
150 151 152 |
# File 'lib/repo.rb', line 150 def add(file_pattern) @git.add(file_pattern) end |
#bare? ⇒ Boolean Also known as: bare
69 70 71 |
# File 'lib/repo.rb', line 69 def @jrepo. end |
#blob(file_path, revstring = Constants::HEAD) ⇒ Object
Convenience method to retrieve a Blob by name
203 204 205 |
# File 'lib/repo.rb', line 203 def blob(file_path, revstring=Constants::HEAD) Blob.find_blob(@jrepo, file_path, revstring) end |
#branch ⇒ Object
105 106 107 |
# File 'lib/repo.rb', line 105 def branch @jrepo.get_full_branch end |
#branches ⇒ Object
109 110 111 |
# File 'lib/repo.rb', line 109 def branches return @git.branch_list end |
#checkout(branch_name, options = {}) ⇒ Object Also known as: switch
125 126 127 |
# File 'lib/repo.rb', line 125 def checkout(branch_name, = {}) @git.checkout(branch_name, ) end |
#clean(options = {}) ⇒ Object
162 163 164 |
# File 'lib/repo.rb', line 162 def clean( = {}) @git.clean() end |
#commit(message, options = {}) ⇒ Object
158 159 160 |
# File 'lib/repo.rb', line 158 def commit(, = {}) @git.commit(, ) end |
#commits(ref = "master", limit = 100) ⇒ Object
88 89 90 91 |
# File 'lib/repo.rb', line 88 def commits(ref="master", limit=100) = { :limit => limit } Commit.find_all(@jrepo, ref, ) end |
#config ⇒ Object
101 102 103 |
# File 'lib/repo.rb', line 101 def config @config.load end |
#create! ⇒ Object
79 80 81 |
# File 'lib/repo.rb', line 79 def create! @jrepo.create(self.) end |
#create_branch(name) ⇒ Object
113 114 115 |
# File 'lib/repo.rb', line 113 def create_branch(name) @git.create_branch(name) end |
#delete_branch(name) ⇒ Object
117 118 119 |
# File 'lib/repo.rb', line 117 def delete_branch(name) @git.delete_branch(name) end |
#find(sha, type = :any) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/repo.rb', line 166 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 |
#remove(file_pattern) ⇒ Object
154 155 156 |
# File 'lib/repo.rb', line 154 def remove(file_pattern) @git.remove(file_pattern) end |
#rename_branch(old_name, new_name) ⇒ Object
121 122 123 |
# File 'lib/repo.rb', line 121 def rename_branch(old_name, new_name) @git.rename_branch(old_name, new_name) end |
#tags(lightweight = false) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/repo.rb', line 131 def (lightweight = false) = @jrepo..to_hash if lightweight .each_with_object( Hash.new ) do |(key, value), hash| hash[key] = ObjectId.to_string(value.get_object_id) end else = Hash.new .each do |key, value| jtag = @git.resolve_tag(value) if jtag tag = Tag.new(jtag) [key] = tag end end end end |
#tree(file_path, revstring = Constants::HEAD) ⇒ Object
Convenience method to retrieve a Tree by name
208 209 210 |
# File 'lib/repo.rb', line 208 def tree(file_path, revstring=Constants::HEAD) Tree.find_tree(@jrepo, file_path, revstring) end |
#update_ref(commit, force = false, ref = "refs/heads/#{Constants::MASTER}") ⇒ Object
212 213 214 215 216 217 |
# File 'lib/repo.rb', line 212 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 ⇒ Object
Update the info files required for fetching files over the dumb-HTTP protocol
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/repo.rb', line 220 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? ⇒ Boolean
97 98 99 |
# File 'lib/repo.rb', line 97 def valid? @jrepo.get_object_database.exists end |