class Bringit::Wrapper
This class encapsulates all git related functionality for convenience.
Attributes
bringit[R]
Public Class Methods
create(path)
click to toggle source
# File lib/bringit/wrapper.rb, line 18 def self.create(path) raise Error, "Path #{path} already exists." if Pathname.new(path).exist? FileUtils.mkdir_p(File.dirname(path)) Rugged::Repository.init_at(path.to_s, :bare) new(path) end
destroy(path)
click to toggle source
# File lib/bringit/wrapper.rb, line 25 def self.destroy(path) new(path.to_s).bringit.repo_exists? && FileUtils.rm_rf(path) end
new(path)
click to toggle source
# File lib/bringit/wrapper.rb, line 29 def initialize(path) @bringit = Bringit::Repository.new(path.to_s) end
Public Instance Methods
blob(ref, path)
click to toggle source
Query for a blob
# File lib/bringit/wrapper.rb, line 46 def blob(ref, path) Bringit::Blob.find(bringit, ref, path) end
branch_sha(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 64 def branch_sha(name) bringit.find_branch(name)&.dereferenced_target&.sha end
commit(ref)
click to toggle source
# File lib/bringit/wrapper.rb, line 55 def commit(ref) Bringit::Commit.find(bringit, ref) end
create_branch(name, revision)
click to toggle source
Create a branch with name name
at the reference ref
.
# File lib/bringit/wrapper.rb, line 78 def create_branch(name, revision) raise_invalid_name_error(name) unless Ref.name_valid?(name) bringit.create_branch(name, revision) end
create_tag(name, revision, annotation = nil)
click to toggle source
If annotation
is not nil
, it will cause the creation of an annotated tag object. annotation
has to contain the following key value pairs:
- :tagger
-
An optional Hash containing a git signature. Defaults to the signature from the configuration if only `:message` is given. Will cause the creation of an annotated tag object if present.
- :message
-
An optional string containing the message for the new tag.
# File lib/bringit/wrapper.rb, line 100 def create_tag(name, revision, annotation = nil) raise_invalid_name_error(name) unless Ref.name_valid?(name) rugged.tags.create(name, revision, annotation) find_tag(name) rescue Rugged::TagError => error raise Bringit::Repository::InvalidRef, error.message end
default_branch()
click to toggle source
# File lib/bringit/wrapper.rb, line 68 def default_branch bringit.discover_default_branch end
default_branch=(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 72 def default_branch=(name) ref = "refs/heads/#{name}" unless name.start_with?('refs/heads/') rugged.head = ref end
diff_from_parent(ref = default_branch, options = {})
click to toggle source
# File lib/bringit/wrapper.rb, line 116 def diff_from_parent(ref = default_branch, options = {}) Commit.find(bringit, ref).diffs(options) end
find_branch(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 83 def find_branch(name) Bringit::Branch.find(self, name) end
find_tag(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 108 def find_tag(name) Bringit::Tag.find(self, name) end
log(options)
click to toggle source
# File lib/bringit/wrapper.rb, line 120 def log(options) result = bringit.log(options) return result if options[:only_commit_sha] result.map do |commit| Bringit::Commit.new(commit, bringit) end end
path()
click to toggle source
# File lib/bringit/wrapper.rb, line 39 def path Pathname.new(bringit. instance_variable_get(:@attributes). instance_variable_get(:@path)) end
path_exists?(ref, path)
click to toggle source
Query for a tree
# File lib/bringit/wrapper.rb, line 60 def path_exists?(ref, path) !blob(ref, path).nil? || tree(ref, path).any? end
repo_exists?()
click to toggle source
# File lib/bringit/wrapper.rb, line 33 def repo_exists? bringit.repo_exists? rescue Bringit::Repository::NoRepository false end
rm_branch(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 87 def rm_branch(name) rugged.branches.delete(name) if find_branch(name) end
rm_tag(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 112 def rm_tag(name) rugged.tags.delete(name) if find_tag(name) end
tree(ref, path)
click to toggle source
Query for a tree
# File lib/bringit/wrapper.rb, line 51 def tree(ref, path) Bringit::Tree.where(bringit, ref, path) end
Protected Instance Methods
raise_invalid_name_error(name)
click to toggle source
# File lib/bringit/wrapper.rb, line 130 def raise_invalid_name_error(name) url = 'https://git-scm.com/docs/git-check-ref-format' raise ::Bringit::InvalidRefName, %(Name "#{name}" is invalid. See #{url} for a valid format.) end