Class: Git::Daily::Init
Instance Method Summary
collapse
Methods inherited from Command
branches, clean?, current_branch, develop, has_branch?, has_remote_branch?, #initialize, logurl, master, merged_branches, pull_request_url, release_branches, remote, remote_branch, remotes
Instance Method Details
#help ⇒ Object
13
14
15
|
# File 'lib/git-daily/command/init.rb', line 13
def help
"init\tInitialize git daily"
end
|
#option ⇒ Object
9
10
11
|
# File 'lib/git-daily/command/init.rb', line 9
def option
OptionParser.new
end
|
#run ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/git-daily/command/init.rb', line 17
def run
r = `git config --bool gitdaily.init`
if r.chomp == "true"
return nil
end
remotes = `git config --list`.split(/\n/).select {|a| a[/^remote\.([^\.]+)\.url/] }
if remotes.empty?
raise "don't have remote repojitory"
end
remotes.map! {|r| r[/^remote\.([^\.]+)\.url=(.*)/, 1] }
selected_url = nil
if remotes.size >= 2
puts "Choose your remote url:"
i = 0
remotes.each do |v|
puts " #{i}: #{v}"
i += 1
end
print " > "
n = gets.to_i
selected_url = remotes[n]
else
selected_url = remotes[0]
end
r = `git config gitdaily.remote #{selected_url}`
puts "Your remote is [#{selected_url}]"
Git::Daily.application.remote = selected_url
print "Name master branch [master]: "
master = gets.strip
if master.empty?
master = "master"
end
`git config gitdaily.master #{master}`
print "Name develop branch [develop]: "
develop = gets.strip
if develop.empty?
develop = "develop"
end
`git config gitdaily.develop #{develop}`
unless Command.has_branch? develop
remote = Command.remote
if remote and Command.has_remote_branch?(remote, develop)
`git checkout #{develop}`
else
`git checkout -b #{develop}`
if remote
`git push #{remote} #{develop}`
end
end
end
`git config gitdaily.init true`
puts
puts "git-daily completed to initialize."
selected_url
end
|
#usage ⇒ Object
85
86
87
88
89
|
# File 'lib/git-daily/command/init.rb', line 85
def usage
<<-EOS
Usage: git daily init
EOS
end
|