Class: Braid::Operations::Git
- Inherits:
-
Proxy
- Object
- Proxy
- Braid::Operations::Git
show all
- Defined in:
- lib/braid/operations.rb
Instance Method Summary
collapse
-
#apply(diff, *args) ⇒ Object
-
#branch ⇒ Object
-
#checkout(treeish) ⇒ Object
-
#clone(*args) ⇒ Object
-
#commit(message, *args) ⇒ Object
-
#diff_tree(src_tree, dst_tree, prefix = nil) ⇒ Object
-
#ensure_clean! ⇒ Object
-
#fetch(remote = nil) ⇒ Object
-
#head ⇒ Object
-
#merge_base(target, source) ⇒ Object
Returns the base commit or nil.
-
#merge_ours(opt) ⇒ Object
-
#merge_recursive(base_hash, local_hash, remote_hash) ⇒ Object
-
#merge_subtree(opt) ⇒ Object
-
#read_tree_prefix(treeish, prefix) ⇒ Object
-
#remote_add(remote, path, branch) ⇒ Object
-
#remote_url(remote) ⇒ Object
Checks git and svn remotes.
-
#reset_hard(target) ⇒ Object
-
#rev_parse(opt) ⇒ Object
-
#rm_r(path) ⇒ Object
-
#status_clean? ⇒ Boolean
-
#tree_hash(path, treeish = "HEAD") ⇒ Object
Methods inherited from Proxy
command, #require_version, #require_version!, #version
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Braid::Operations::Proxy
Instance Method Details
#apply(diff, *args) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/braid/operations.rb', line 267
def apply(diff, *args)
err = nil
status = Open4.popen4("git apply --index --whitespace=nowarn #{args.join(' ')} -") do |pid, stdin, stdout, stderr|
stdin.puts(diff)
stdin.close
err = stderr.read
end.exitstatus
raise ShellExecutionError, err unless status == 0
true
end
|
#branch ⇒ Object
262
263
264
265
|
# File 'lib/braid/operations.rb', line 262
def branch
status, out, err = exec!("git branch | grep '*'")
out[2..-1]
end
|
#checkout(treeish) ⇒ Object
164
165
166
167
|
# File 'lib/braid/operations.rb', line 164
def checkout(treeish)
invoke(:checkout, treeish)
true
end
|
#clone(*args) ⇒ Object
279
280
281
282
|
# File 'lib/braid/operations.rb', line 279
def clone(*args)
invoke(:clone, *args)
end
|
#commit(message, *args) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/braid/operations.rb', line 141
def commit(message, *args)
commit_message_file = Tempfile.new("braid_commit", ".")
commit_message_file.print("Braid: " + message)
commit_message_file.flush
status, out, err = exec("git commit -F #{commit_message_file.path} --no-verify #{args.join(' ')}")
commit_message_file.unlink
if status == 0
true
elsif out.match(/nothing.* to commit/)
false
else
raise ShellExecutionError, err
end
end
|
#diff_tree(src_tree, dst_tree, prefix = nil) ⇒ Object
242
243
244
245
246
247
|
# File 'lib/braid/operations.rb', line 242
def diff_tree(src_tree, dst_tree, prefix = nil)
cmd = "git diff-tree -p --binary #{src_tree} #{dst_tree}"
cmd << " --src-prefix=a/#{prefix}/ --dst-prefix=b/#{prefix}/" if prefix
status, out, err = exec!(cmd)
out
end
|
#ensure_clean! ⇒ Object
254
255
256
|
# File 'lib/braid/operations.rb', line 254
def ensure_clean!
status_clean? || raise(LocalChangesPresent)
end
|
#fetch(remote = nil) ⇒ Object
158
159
160
161
162
|
# File 'lib/braid/operations.rb', line 158
def fetch(remote = nil)
args = remote && "-n #{remote}"
sh("git fetch #{args} 2>&1 >/dev/null")
end
|
#head ⇒ Object
258
259
260
|
# File 'lib/braid/operations.rb', line 258
def head
rev_parse("HEAD")
end
|
#merge_base(target, source) ⇒ Object
Returns the base commit or nil.
170
171
172
173
174
|
# File 'lib/braid/operations.rb', line 170
def merge_base(target, source)
invoke(:merge_base, target, source)
rescue ShellExecutionError
nil
end
|
#merge_ours(opt) ⇒ Object
206
207
208
209
|
# File 'lib/braid/operations.rb', line 206
def merge_ours(opt)
invoke(:merge, "-s ours --no-commit", opt)
true
end
|
#merge_recursive(base_hash, local_hash, remote_hash) ⇒ Object
220
221
222
223
224
225
|
# File 'lib/braid/operations.rb', line 220
def merge_recursive(base_hash, local_hash, remote_hash)
invoke(:merge_recursive, base_hash, "-- #{local_hash} #{remote_hash}")
true
rescue ShellExecutionError
raise MergeError
end
|
#merge_subtree(opt) ⇒ Object
212
213
214
215
216
217
218
|
# File 'lib/braid/operations.rb', line 212
def merge_subtree(opt)
invoke(:merge, "-s subtree --no-commit --no-ff", opt)
true
rescue ShellExecutionError
raise MergeError
end
|
#read_tree_prefix(treeish, prefix) ⇒ Object
227
228
229
230
|
# File 'lib/braid/operations.rb', line 227
def read_tree_prefix(treeish, prefix)
invoke(:read_tree, "--prefix=#{prefix}/ -u", treeish)
true
end
|
#remote_add(remote, path, branch) ⇒ Object
183
184
185
186
|
# File 'lib/braid/operations.rb', line 183
def remote_add(remote, path, branch)
invoke(:remote, "add", "-t #{branch} -m #{branch}", remote, path)
true
end
|
#remote_url(remote) ⇒ Object
Checks git and svn remotes.
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/braid/operations.rb', line 189
def remote_url(remote)
key = "remote.#{remote}.url"
begin
invoke(:config, key)
rescue ShellExecutionError
invoke(:config, "svn-#{key}")
end
rescue ShellExecutionError
nil
end
|
#reset_hard(target) ⇒ Object
200
201
202
203
|
# File 'lib/braid/operations.rb', line 200
def reset_hard(target)
invoke(:reset, "--hard", target)
true
end
|
#rm_r(path) ⇒ Object
232
233
234
235
|
# File 'lib/braid/operations.rb', line 232
def rm_r(path)
invoke(:rm, "-r", path)
true
end
|
#status_clean? ⇒ Boolean
249
250
251
252
|
# File 'lib/braid/operations.rb', line 249
def status_clean?
status, out, err = exec("git status")
!out.split("\n").grep(/nothing to commit/).empty?
end
|
#tree_hash(path, treeish = "HEAD") ⇒ Object
237
238
239
240
|
# File 'lib/braid/operations.rb', line 237
def tree_hash(path, treeish = "HEAD")
out = invoke(:ls_tree, treeish, "-d", path)
out.split[2]
end
|