Class: GitWrapper::Repository
- Inherits:
-
Object
- Object
- GitWrapper::Repository
- Defined in:
- lib/git_wrapper/repository.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#log_error ⇒ Object
readonly
Returns the value of attribute log_error.
-
#log_output ⇒ Object
readonly
Returns the value of attribute log_output.
Instance Method Summary collapse
- #add(file_name) ⇒ Object
- #add_all ⇒ Object
- #add_remote(name, url) ⇒ Object
- #bare? ⇒ Boolean
- #branch(name, commit = nil) ⇒ Object
- #branches ⇒ Object
- #checkout(commit, new_branch = nil) ⇒ Object
- #commit(message, options = {}) ⇒ Object
- #config(key = nil, value = nil) ⇒ Object
- #current_branch ⇒ Object
- #diff(commit) ⇒ Object
- #diff_reverse(commit) ⇒ Object
- #diff_tree(commit) ⇒ Object
- #fetch(remote = nil) ⇒ Object
- #init ⇒ Object
- #init_bare ⇒ Object
-
#initialize(location) ⇒ Repository
constructor
A new instance of Repository.
- #initialized? ⇒ Boolean
- #log(options = {}) ⇒ Object
- #merge(commit) ⇒ Object
- #pull(remote = 'origin', branch = 'master') ⇒ Object
- #push(remote = 'origin', branch = 'master') ⇒ Object
- #push_tags(remote = 'origin') ⇒ Object
- #remotes ⇒ Object
- #remove(file_name) ⇒ Object
- #remove_branch(name, remote = nil) ⇒ Object
- #remove_remote(name) ⇒ Object
- #remove_tag(name) ⇒ Object
- #reset(options = {}) ⇒ Object
- #rev_list(options = {}) ⇒ Object
- #rev_list_count(options = {}) ⇒ Object
- #revert(commit) ⇒ Object
- #show(file_name, commit = nil) ⇒ Object
- #show_base(file_name) ⇒ Object
- #show_mine(file_name) ⇒ Object
- #show_theirs(file_name) ⇒ Object
- #status ⇒ Object
- #tag(name, commit = nil) ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(location) ⇒ Repository
Returns a new instance of Repository.
7 8 9 10 11 |
# File 'lib/git_wrapper/repository.rb', line 7 def initialize(location) @location = location @log_output = [] @log_error = [] end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
3 4 5 |
# File 'lib/git_wrapper/repository.rb', line 3 def location @location end |
#log_error ⇒ Object (readonly)
Returns the value of attribute log_error.
5 6 7 |
# File 'lib/git_wrapper/repository.rb', line 5 def log_error @log_error end |
#log_output ⇒ Object (readonly)
Returns the value of attribute log_output.
4 5 6 |
# File 'lib/git_wrapper/repository.rb', line 4 def log_output @log_output end |
Instance Method Details
#add(file_name) ⇒ Object
38 39 40 |
# File 'lib/git_wrapper/repository.rb', line 38 def add(file_name) execute(Commands::Add.new(@location).file(file_name)) end |
#add_all ⇒ Object
42 43 44 |
# File 'lib/git_wrapper/repository.rb', line 42 def add_all execute(Commands::Add.new(@location).all) end |
#add_remote(name, url) ⇒ Object
60 61 62 |
# File 'lib/git_wrapper/repository.rb', line 60 def add_remote(name, url) execute(Commands::Remote.new(@location).name(name).add(url)) end |
#bare? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/git_wrapper/repository.rb', line 27 def Dir.exist?("#{@location}/hooks") && Dir.exist?("#{@location}/info") && Dir.exist?("#{@location}/objects") && Dir.exist?("#{@location}/refs") end |
#branch(name, commit = nil) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/git_wrapper/repository.rb', line 131 def branch(name, commit=nil) if commit.nil? execute(Commands::Branch.new(@location).create(name)) else execute(Commands::Branch.new(@location).create(name).from(commit)) end end |
#branches ⇒ Object
122 123 124 |
# File 'lib/git_wrapper/repository.rb', line 122 def branches execute(Commands::Branch.new(@location).list) end |
#checkout(commit, new_branch = nil) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/git_wrapper/repository.rb', line 147 def checkout(commit, new_branch=nil) if commit.nil? execute(Commands::Checkout.new(@location).commit(commit)) else execute(Commands::Checkout.new(@location).commit(commit).into(new_branch)) end end |
#commit(message, options = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/git_wrapper/repository.rb', line 46 def commit(, ={}) command = Commands::Commit.new(@location).() command.([:author_name], [:author_email]) if [:author_name] && [:author_email] execute(command) end |
#config(key = nil, value = nil) ⇒ Object
210 211 212 213 214 215 |
# File 'lib/git_wrapper/repository.rb', line 210 def config(key=nil, value=nil) command = Commands::Config.new(@location) command.key(key) if key command.value(value) if value execute(command) end |
#current_branch ⇒ Object
126 127 128 129 |
# File 'lib/git_wrapper/repository.rb', line 126 def current_branch branch = execute(Commands::Branch.new(@location).current) branch.nil? ? 'master' : branch end |
#diff(commit) ⇒ Object
183 184 185 |
# File 'lib/git_wrapper/repository.rb', line 183 def diff(commit) execute(Commands::Diff.new(@location).with(commit)) end |
#diff_reverse(commit) ⇒ Object
187 188 189 |
# File 'lib/git_wrapper/repository.rb', line 187 def diff_reverse(commit) execute(Commands::Diff.new(@location).with(commit).reverse) end |
#diff_tree(commit) ⇒ Object
191 192 193 |
# File 'lib/git_wrapper/repository.rb', line 191 def diff_tree(commit) execute(Commands::DiffTree.new(@location).commit(commit)) end |
#fetch(remote = nil) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/git_wrapper/repository.rb', line 175 def fetch(remote=nil) if remote.nil? execute(Commands::Fetch.new(@location).all) else execute(Commands::Fetch.new(@location).remote(remote)) end end |
#init ⇒ Object
13 14 15 16 |
# File 'lib/git_wrapper/repository.rb', line 13 def init FileUtils.mkpath(@location) unless Dir.exist?(@location) execute(Commands::Init.new(@location)) end |
#init_bare ⇒ Object
18 19 20 21 |
# File 'lib/git_wrapper/repository.rb', line 18 def FileUtils.mkpath(@location) unless Dir.exist?(@location) execute(Commands::Init.new(@location).) end |
#initialized? ⇒ Boolean
23 24 25 |
# File 'lib/git_wrapper/repository.rb', line 23 def initialized? Dir.exist?("#{@location}/.git") || end |
#log(options = {}) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/git_wrapper/repository.rb', line 98 def log(={}) command = Commands::Log.new(@location) .each do |option, value| command.send option, value if value && !value.to_s.strip.empty? end execute(command) end |
#merge(commit) ⇒ Object
171 172 173 |
# File 'lib/git_wrapper/repository.rb', line 171 def merge(commit) execute(Commands::Merge.new(@location).commit(commit)) end |
#pull(remote = 'origin', branch = 'master') ⇒ Object
68 69 70 |
# File 'lib/git_wrapper/repository.rb', line 68 def pull(remote='origin', branch='master') execute(Commands::Pull.new(@location).remote(remote).branch(branch)) end |
#push(remote = 'origin', branch = 'master') ⇒ Object
72 73 74 |
# File 'lib/git_wrapper/repository.rb', line 72 def push(remote='origin', branch='master') execute(Commands::Push.new(@location).remote(remote).branch(branch)) end |
#push_tags(remote = 'origin') ⇒ Object
76 77 78 |
# File 'lib/git_wrapper/repository.rb', line 76 def (remote='origin') execute(Commands::Push.new(@location).remote(remote).) end |
#remotes ⇒ Object
56 57 58 |
# File 'lib/git_wrapper/repository.rb', line 56 def remotes execute(Commands::Remote.new(@location).list) end |
#remove(file_name) ⇒ Object
52 53 54 |
# File 'lib/git_wrapper/repository.rb', line 52 def remove(file_name) execute(Commands::Remove.new(@location).file(file_name)) end |
#remove_branch(name, remote = nil) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/git_wrapper/repository.rb', line 139 def remove_branch(name, remote=nil) if remote.nil? execute(Commands::Branch.new(@location).remove(name)) else execute(Commands::Branch.new(@location).remove(name).remote(remote)) end end |
#remove_remote(name) ⇒ Object
64 65 66 |
# File 'lib/git_wrapper/repository.rb', line 64 def remove_remote(name) execute(Commands::Remote.new(@location).name(name).remove) end |
#remove_tag(name) ⇒ Object
167 168 169 |
# File 'lib/git_wrapper/repository.rb', line 167 def remove_tag(name) execute(Commands::Tag.new(@location).remove(name)) end |
#reset(options = {}) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/git_wrapper/repository.rb', line 203 def reset(={}) command = Commands::Reset.new(@location) command.commit([:commit]) if [:commit] command.send([:mode]) if [:mode] execute(command) end |
#rev_list(options = {}) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/git_wrapper/repository.rb', line 106 def rev_list(={}) command = Commands::RevList.new(@location) .each do |option, value| command.send option, value if value && !value.to_s.strip.empty? end execute(command) end |
#rev_list_count(options = {}) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/git_wrapper/repository.rb', line 114 def rev_list_count(={}) command = Commands::RevList.new(@location).count .each do |option, value| command.send option, value if value && !value.to_s.strip.empty? end execute(command) end |
#revert(commit) ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/git_wrapper/repository.rb', line 195 def revert(commit) if log(:commit => commit).merge? execute(Commands::Revert.new(@location).merge(commit)) else execute(Commands::Revert.new(@location).commit(commit)) end end |
#show(file_name, commit = nil) ⇒ Object
80 81 82 83 84 |
# File 'lib/git_wrapper/repository.rb', line 80 def show(file_name, commit=nil) command = Commands::Show.new(@location).file(file_name) command.commit(commit) unless commit.nil? execute(command) end |
#show_base(file_name) ⇒ Object
86 87 88 |
# File 'lib/git_wrapper/repository.rb', line 86 def show_base(file_name) execute(Commands::Show.new(@location).file(file_name).base) end |
#show_mine(file_name) ⇒ Object
90 91 92 |
# File 'lib/git_wrapper/repository.rb', line 90 def show_mine(file_name) execute(Commands::Show.new(@location).file(file_name).mine) end |
#show_theirs(file_name) ⇒ Object
94 95 96 |
# File 'lib/git_wrapper/repository.rb', line 94 def show_theirs(file_name) execute(Commands::Show.new(@location).file(file_name).theirs) end |
#status ⇒ Object
34 35 36 |
# File 'lib/git_wrapper/repository.rb', line 34 def status execute(Commands::Status.new(@location)) end |