Class: Gub::Git
- Inherits:
-
Object
show all
- Defined in:
- lib/gub/clients/git.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
23
24
25
|
# File 'lib/gub/clients/git.rb', line 23
def method_missing meth, *args, &block
self.run(meth, *args)
end
|
Instance Attribute Details
#default_options ⇒ Object
Returns the value of attribute default_options.
5
6
7
|
# File 'lib/gub/clients/git.rb', line 5
def default_options
@default_options
end
|
Instance Method Details
#clone(repo, *args) ⇒ Object
Due to clone being a Ruby magic method, we have to override it
19
20
21
|
# File 'lib/gub/clients/git.rb', line 19
def clone repo, *args
self.run('clone', repo, *args)
end
|
#remotes ⇒ Object
14
15
16
|
# File 'lib/gub/clients/git.rb', line 14
def remotes
`git remote -v | grep fetch | awk '{print $2}' | cut -d ':' -f 2`.split("\n").split(' ').map(&:chop)
end
|
#run(command, *args) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/gub/clients/git.rb', line 28
def run command, *args
command = command.to_s
default_options = []
default_options << '-q'
cmd = []
cmd << 'git'
cmd << command
if args.any?
arguments = args
unless ['clone', 'remote', 'checkout'].include?(command)
arguments = arguments.zip(default_options).flatten!
end
cmd << arguments.join(' ').to_s
end
cmd_line = cmd.join(' ')
Gub.log.debug "Running git command: #{cmd_line}"
out = `#{cmd_line}`.split("\n").map(&:strip)
out
end
|
#sync(remote) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/gub/clients/git.rb', line 7
def sync remote
self.checkout('master')
self.fetch(remote)
self.merge("#{remote}/master")
self.push('origin', '--all')
end
|