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
- #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
- #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
117 118 119 120 121 122 123 |
# File 'lib/git_wrapper/repository.rb', line 117 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
108 109 110 |
# File 'lib/git_wrapper/repository.rb', line 108 def branches execute(Commands::Branch.new(@location).list) end |
#checkout(commit, new_branch = nil) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/git_wrapper/repository.rb', line 133 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
192 193 194 195 196 197 |
# File 'lib/git_wrapper/repository.rb', line 192 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
112 113 114 115 |
# File 'lib/git_wrapper/repository.rb', line 112 def current_branch branch = execute(Commands::Branch.new(@location).current) branch.nil? ? 'master' : branch end |
#diff(commit) ⇒ Object
169 170 171 |
# File 'lib/git_wrapper/repository.rb', line 169 def diff(commit) execute(Commands::Diff.new(@location).with(commit)) end |
#diff_reverse(commit) ⇒ Object
173 174 175 |
# File 'lib/git_wrapper/repository.rb', line 173 def diff_reverse(commit) execute(Commands::Diff.new(@location).with(commit).reverse) end |
#fetch(remote = nil) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/git_wrapper/repository.rb', line 161 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 105 106 |
# File 'lib/git_wrapper/repository.rb', line 98 def log(={}) if [:file_name] execute(Commands::Log.new(@location).file([:file_name])) elsif [:commit] execute(Commands::Log.new(@location).commit([:commit])) else execute(Commands::Log.new(@location)) end end |
#merge(commit) ⇒ Object
157 158 159 |
# File 'lib/git_wrapper/repository.rb', line 157 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
125 126 127 128 129 130 131 |
# File 'lib/git_wrapper/repository.rb', line 125 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
153 154 155 |
# File 'lib/git_wrapper/repository.rb', line 153 def remove_tag(name) execute(Commands::Tag.new(@location).remove(name)) end |
#reset(options = {}) ⇒ Object
185 186 187 188 189 190 |
# File 'lib/git_wrapper/repository.rb', line 185 def reset(={}) command = Commands::Reset.new(@location) command.commit([:commit]) if [:commit] command.send([:mode]) if [:mode] execute(command) end |
#revert(commit) ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/git_wrapper/repository.rb', line 177 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 |