Class: GitWrapper::Commands::Branch
- Inherits:
-
Git
- Object
- Git
- GitWrapper::Commands::Branch
show all
- Defined in:
- lib/git_wrapper/commands/branch.rb
Instance Attribute Summary
Attributes inherited from Git
#error, #location_folder, #output
Instance Method Summary
collapse
Methods inherited from Git
#execute, #initialize, #to_relative_path
Instance Method Details
#command ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/git_wrapper/commands/branch.rb', line 37
def command
command = 'branch '
if @mode == :create
command += "#{@name} #{@commit.nil? ? '' : @commit}"
elsif @mode == :remove
if @remote.nil?
command += "-D #{@name}"
else
command = "push #{@remote} --delete #{@name}"
end
elsif @mode == :list || @mode == :current
command += '-a'
else
raise 'Unespecified branch mode'
end
command
end
|
#create(name) ⇒ Object
5
6
7
8
9
|
# File 'lib/git_wrapper/commands/branch.rb', line 5
def create(name)
@mode = :create
@name = name
self
end
|
#current ⇒ Object
32
33
34
35
|
# File 'lib/git_wrapper/commands/branch.rb', line 32
def current
@mode = :current
self
end
|
#from(commit) ⇒ Object
11
12
13
14
|
# File 'lib/git_wrapper/commands/branch.rb', line 11
def from(commit)
@commit = commit
self
end
|
#list ⇒ Object
27
28
29
30
|
# File 'lib/git_wrapper/commands/branch.rb', line 27
def list
@mode = :list
self
end
|
#remote(remote) ⇒ Object
22
23
24
25
|
# File 'lib/git_wrapper/commands/branch.rb', line 22
def remote(remote)
@remote = remote
self
end
|
#remove(name) ⇒ Object
16
17
18
19
20
|
# File 'lib/git_wrapper/commands/branch.rb', line 16
def remove(name)
@mode = :remove
@name = name
self
end
|
#result ⇒ Object
57
58
59
60
61
|
# File 'lib/git_wrapper/commands/branch.rb', line 57
def result
return result_list if @mode == :list
return result_current if @mode == :current
super
end
|
#result_current ⇒ Object
67
68
69
|
# File 'lib/git_wrapper/commands/branch.rb', line 67
def result_current
output.split("\n").select{|b| b.start_with?('*')}.map{|b| b[2..b.length]}.first
end
|
#result_list ⇒ Object
63
64
65
|
# File 'lib/git_wrapper/commands/branch.rb', line 63
def result_list
output.split("\n").map{|b| b[2..b.length]}
end
|