Class: Bringit::Wrapper
Overview
This class encapsulates all git related functionality for convenience.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
clone, valid_remote?
Methods included from Pulling
#pull
Methods included from Committing
#commit_multichange, #create_file, #mkdir, #remove_file, #rename_and_update_file, #rename_file, #update_file
#add_merge_data, #conflict_hash, #conflict_on_update, #conflicts, #create_merging_commit, #create_user_commit, #diverged?, #merge, #merge_if_needed, #raise_head_changed_error, #with_temp_user_reference
Constructor Details
#initialize(path) ⇒ Wrapper
Returns a new instance of Wrapper.
29
30
31
|
# File 'lib/bringit/wrapper.rb', line 29
def initialize(path)
@bringit = Bringit::Repository.new(path.to_s)
end
|
Instance Attribute Details
#bringit ⇒ Object
Returns the value of attribute bringit.
13
14
15
|
# File 'lib/bringit/wrapper.rb', line 13
def bringit
@bringit
end
|
Class Method Details
.create(path) ⇒ Object
18
19
20
21
22
23
|
# 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) ⇒ Object
25
26
27
|
# File 'lib/bringit/wrapper.rb', line 25
def self.destroy(path)
new(path.to_s).bringit.repo_exists? && FileUtils.rm_rf(path)
end
|
Instance Method Details
#blob(ref, path) ⇒ Object
46
47
48
|
# File 'lib/bringit/wrapper.rb', line 46
def blob(ref, path)
Bringit::Blob.find(bringit, ref, path)
end
|
#branch_sha(name) ⇒ Object
64
65
66
|
# File 'lib/bringit/wrapper.rb', line 64
def branch_sha(name)
bringit.find_branch(name)&.dereferenced_target&.sha
end
|
#commit(ref) ⇒ Object
55
56
57
|
# File 'lib/bringit/wrapper.rb', line 55
def commit(ref)
Bringit::Commit.find(bringit, ref)
end
|
#create_branch(name, revision) ⇒ Object
Create a branch with name name
at the reference ref
.
78
79
80
81
|
# 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) ⇒ Object
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.
100
101
102
103
104
105
106
|
# 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 ⇒ Object
68
69
70
|
# File 'lib/bringit/wrapper.rb', line 68
def default_branch
bringit.discover_default_branch
end
|
#default_branch=(name) ⇒ Object
72
73
74
75
|
# 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 = {}) ⇒ Object
116
117
118
|
# 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) ⇒ Object
83
84
85
|
# File 'lib/bringit/wrapper.rb', line 83
def find_branch(name)
Bringit::Branch.find(self, name)
end
|
#find_tag(name) ⇒ Object
108
109
110
|
# File 'lib/bringit/wrapper.rb', line 108
def find_tag(name)
Bringit::Tag.find(self, name)
end
|
#log(options) ⇒ Object
120
121
122
123
124
125
126
|
# 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 ⇒ Object
39
40
41
42
43
|
# 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) ⇒ Boolean
60
61
62
|
# File 'lib/bringit/wrapper.rb', line 60
def path_exists?(ref, path)
!blob(ref, path).nil? || tree(ref, path).any?
end
|
#repo_exists? ⇒ Boolean
33
34
35
36
37
|
# File 'lib/bringit/wrapper.rb', line 33
def repo_exists?
bringit.repo_exists?
rescue Bringit::Repository::NoRepository
false
end
|
#rm_branch(name) ⇒ Object
87
88
89
|
# File 'lib/bringit/wrapper.rb', line 87
def rm_branch(name)
rugged.branches.delete(name) if find_branch(name)
end
|
#rm_tag(name) ⇒ Object
112
113
114
|
# File 'lib/bringit/wrapper.rb', line 112
def rm_tag(name)
rugged.tags.delete(name) if find_tag(name)
end
|
#tree(ref, path) ⇒ Object
51
52
53
|
# File 'lib/bringit/wrapper.rb', line 51
def tree(ref, path)
Bringit::Tree.where(bringit, ref, path)
end
|