shkeeper 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/.gitignore +8 -0
  3. data/.idea/bigkeeper.iml +68 -0
  4. data/.idea/modules.xml +8 -0
  5. data/.idea/vcs.xml +6 -0
  6. data/CODE_OF_CONDUCT.md +46 -0
  7. data/CONTRIBUTING.md +70 -0
  8. data/Gemfile +10 -0
  9. data/Gemfile.lock +145 -0
  10. data/LICENSE +21 -0
  11. data/README.md +113 -0
  12. data/big_keeper.gemspec +50 -0
  13. data/bin/big +14 -0
  14. data/bin/koo +14 -0
  15. data/bin/setup +8 -0
  16. data/bin/sh +14 -0
  17. data/docs/en-US/FEATURE.md +0 -0
  18. data/docs/en-US/README.md +54 -0
  19. data/docs/zh-CN/BIGKEEPER_FILE.md +84 -0
  20. data/docs/zh-CN/FEATURE&HOTFIX.md +88 -0
  21. data/docs/zh-CN/IMAGE.md +0 -0
  22. data/docs/zh-CN/PODFILE.md +43 -0
  23. data/docs/zh-CN/README.md +113 -0
  24. data/docs/zh-CN/RECOMMEND.md +22 -0
  25. data/docs/zh-CN/RELEASE.md +60 -0
  26. data/docs/zh-CN/SPEC.md +39 -0
  27. data/lib/big_keeper/command/feature&hotfix/delete.rb +40 -0
  28. data/lib/big_keeper/command/feature&hotfix/finish.rb +57 -0
  29. data/lib/big_keeper/command/feature&hotfix/list.rb +63 -0
  30. data/lib/big_keeper/command/feature&hotfix/publish.rb +56 -0
  31. data/lib/big_keeper/command/feature&hotfix/pull.rb +26 -0
  32. data/lib/big_keeper/command/feature&hotfix/push.rb +27 -0
  33. data/lib/big_keeper/command/feature&hotfix/rebase.rb +32 -0
  34. data/lib/big_keeper/command/feature&hotfix/start.rb +94 -0
  35. data/lib/big_keeper/command/feature&hotfix/switch.rb +48 -0
  36. data/lib/big_keeper/command/feature&hotfix/update.rb +74 -0
  37. data/lib/big_keeper/command/feature&hotfix.rb +169 -0
  38. data/lib/big_keeper/command/image/image.rb +0 -0
  39. data/lib/big_keeper/command/image.rb +28 -0
  40. data/lib/big_keeper/command/pod/podfile.rb +69 -0
  41. data/lib/big_keeper/command/pod.rb +42 -0
  42. data/lib/big_keeper/command/release/home.rb +91 -0
  43. data/lib/big_keeper/command/release/module.rb +61 -0
  44. data/lib/big_keeper/command/release.rb +75 -0
  45. data/lib/big_keeper/command/spec/add.rb +9 -0
  46. data/lib/big_keeper/command/spec/analyze.rb +88 -0
  47. data/lib/big_keeper/command/spec/delete.rb +9 -0
  48. data/lib/big_keeper/command/spec/list.rb +19 -0
  49. data/lib/big_keeper/command/spec/search.rb +9 -0
  50. data/lib/big_keeper/command/spec/sync.rb +12 -0
  51. data/lib/big_keeper/command/spec.rb +78 -0
  52. data/lib/big_keeper/dependency/dep_gradle_operator.rb +56 -0
  53. data/lib/big_keeper/dependency/dep_operator.rb +32 -0
  54. data/lib/big_keeper/dependency/dep_pod_operator.rb +131 -0
  55. data/lib/big_keeper/dependency/dep_service.rb +14 -0
  56. data/lib/big_keeper/dependency/dep_type.rb +33 -0
  57. data/lib/big_keeper/model/gitflow_type.rb +43 -0
  58. data/lib/big_keeper/model/library_model.rb +116 -0
  59. data/lib/big_keeper/model/operate_type.rb +27 -0
  60. data/lib/big_keeper/model/podfile_model.rb +33 -0
  61. data/lib/big_keeper/service/git_service.rb +261 -0
  62. data/lib/big_keeper/service/module_service.rb +161 -0
  63. data/lib/big_keeper/service/stash_service.rb +58 -0
  64. data/lib/big_keeper/util/bigkeeper_parser.rb +244 -0
  65. data/lib/big_keeper/util/cache_operator.rb +149 -0
  66. data/lib/big_keeper/util/code_operator.rb +37 -0
  67. data/lib/big_keeper/util/file_operator.rb +33 -0
  68. data/lib/big_keeper/util/git_operator.rb +226 -0
  69. data/lib/big_keeper/util/gitflow_operator.rb +51 -0
  70. data/lib/big_keeper/util/gradle_operator.rb +209 -0
  71. data/lib/big_keeper/util/info_plist_operator.rb +46 -0
  72. data/lib/big_keeper/util/leancloud_logger.rb +72 -0
  73. data/lib/big_keeper/util/list_generator.rb +101 -0
  74. data/lib/big_keeper/util/logger.rb +46 -0
  75. data/lib/big_keeper/util/pod_operator.rb +71 -0
  76. data/lib/big_keeper/util/podfile_detector.rb +137 -0
  77. data/lib/big_keeper/util/podfile_module.rb +63 -0
  78. data/lib/big_keeper/util/podfile_operator.rb +117 -0
  79. data/lib/big_keeper/util/verify_operator.rb +17 -0
  80. data/lib/big_keeper/util/xcode_operator.rb +15 -0
  81. data/lib/big_keeper/version.rb +3 -0
  82. data/lib/big_keeper.rb +71 -0
  83. data/resources/banner.png +0 -0
  84. data/resources/command.png +0 -0
  85. data/resources/keynote/big-keeper-readme-analyze.key +0 -0
  86. data/resources/keynote/big-keeper-readme-example.key +0 -0
  87. data/resources/keynote/big-keeper-readme-feature.key +0 -0
  88. data/resources/keynote/big-keeper-readme-release.key +0 -0
  89. data/resources/readme/big-keeper-readme.001.png +0 -0
  90. metadata +345 -0
@@ -0,0 +1,14 @@
1
+ require 'big_keeper/util/git_operator'
2
+ require 'big_keeper/model/gitflow_type'
3
+ require 'big_keeper/model/operate_type'
4
+ require 'big_keeper/util/logger'
5
+ require 'big_keeper/dependency/dep_type'
6
+
7
+ module BigKeeper
8
+ # Operator for podfile
9
+ class DepService
10
+ def self.dep_operator(path, user)
11
+ DepType.operator(path, user)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ require 'big_keeper/dependency/dep_operator'
2
+ require 'big_keeper/dependency/dep_pod_operator'
3
+ require 'big_keeper/dependency/dep_gradle_operator'
4
+ require 'big_keeper/util/file_operator'
5
+
6
+ module BigKeeper
7
+ module DepType
8
+ NONE = 0
9
+ COCOAPODS = 1
10
+ GRADLE = 2
11
+
12
+ def self.type(path)
13
+ if FileOperator.definitely_exists?("#{path}/Podfile")
14
+ COCOAPODS
15
+ elsif FileOperator.definitely_exists?("#{path}/build.gradle")
16
+ GRADLE
17
+ else
18
+ NONE
19
+ end
20
+ end
21
+
22
+ def self.operator(path, user)
23
+ operator_type = type(path)
24
+ if COCOAPODS == operator_type
25
+ DepPodOperator.new(path, user)
26
+ elsif GRADLE == operator_type
27
+ DepGradleOperator.new(path, user)
28
+ else
29
+ DepOperator.new(path, user)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module BigKeeper
2
+ module GitflowType
3
+ FEATURE = 1
4
+ HOTFIX = 2
5
+ RELEASE = 3
6
+
7
+ def self.name(type)
8
+ if FEATURE == type
9
+ "feature"
10
+ elsif HOTFIX == type
11
+ "hotfix"
12
+ elsif RELEASE == type
13
+ "release"
14
+ else
15
+ "feature"
16
+ end
17
+ end
18
+
19
+ def self.command(type)
20
+ if FEATURE == type
21
+ :feature
22
+ elsif HOTFIX == type
23
+ :hotfix
24
+ elsif RELEASE == type
25
+ :release
26
+ else
27
+ :feature
28
+ end
29
+ end
30
+
31
+ def self.base_branch(type)
32
+ if FEATURE == type
33
+ "develop"
34
+ elsif HOTFIX == type
35
+ "master"
36
+ elsif RELEASE == type
37
+ "develop"
38
+ else
39
+ "master"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,116 @@
1
+ require 'big_keeper/util/file_operator'
2
+ require 'big_keeper/util/code_operator'
3
+
4
+
5
+ module BigKeeper
6
+ class LibraryModel
7
+ attr_accessor :name, :file_list, :header_file_list, :keyword_list, :spec_library
8
+ def initialize(name)
9
+ @name = name
10
+ @file_list = []
11
+ @header_file_list = []
12
+ @spec_library = []
13
+ @keyword_list = []
14
+ end
15
+
16
+ def get_all_public_file(path)
17
+ all_header = FileOperator.find_all_header_file("#{path}/Pods/#{@name}")
18
+ for file_path in all_header do
19
+ @header_file_list[@header_file_list.size] = file_path
20
+ file_name = File.basename(file_path)
21
+ @keyword_list[@keyword_list.size] = file_name
22
+ in_note = false
23
+ File.foreach(file_path) { |line|
24
+ hash = Hash.new
25
+ hash["in_note"]=in_note
26
+ hash["line"]=line
27
+ OCCodeOperator.in_note_code(hash)
28
+ in_note = hash["in_note"]
29
+ line = hash["line"]
30
+ if line.empty?
31
+ next
32
+ end
33
+ if line.include?("@interface ")
34
+ line[0,line.index("@interface ")+11]=""
35
+ column = line.split(/:/)
36
+ if column.size > 1
37
+ class_name = column[0]
38
+ if class_name.include?("<")
39
+ class_name = class_name[0, class_name.index("<")]
40
+ end
41
+ class_name = class_name.strip
42
+ if (@keyword_list.include?(class_name+".h"))
43
+ @keyword_list.delete(class_name+".h")
44
+ end
45
+ @keyword_list[@keyword_list.size] = class_name
46
+ end
47
+ end
48
+ }
49
+ end
50
+ # if @name == ""
51
+ # puts @keyword_list
52
+ # end
53
+ @file_list = FileOperator.find_all_code_file("#{path}/Pods/#{@name}")
54
+ end
55
+
56
+ def spec_dependece_library(library_keywords_hash)
57
+ if library_keywords_hash.include?(@name)
58
+ library_keywords_hash.delete(@name)
59
+ end
60
+
61
+ for file_path in @file_list do
62
+ # note for coding
63
+ in_note = false
64
+ File.foreach(file_path) { |line|
65
+ hash = Hash.new
66
+ hash["in_note"]=in_note
67
+ hash["line"]=line
68
+ OCCodeOperator.in_note_code(hash)
69
+ in_note = hash["in_note"]
70
+ line = hash["line"]
71
+ if line.empty?
72
+ next
73
+ end
74
+ library_keywords_hash.each {|library_name, keyword_list|
75
+ is_dependence = false
76
+ tip = ""
77
+ for keyword in keyword_list do
78
+ if line.include?(keyword)
79
+ last_char = '.'
80
+ last_index = line.index(keyword)-1
81
+ if last_index >= 0
82
+ last_char = line[last_index]
83
+ end
84
+ next_char = '.'
85
+ next_index = line.index(keyword)+keyword.size
86
+ if next_index < line.size
87
+ next_char = line[next_index]
88
+ end
89
+ if !(((next_char<='z'&&next_char>='a')||(next_char<='Z'&&next_char>='A')||(next_char<='9'&&next_char>='0')||next_char=='_')||((last_char<='z'&&last_char>='a')||(last_char<='Z'&&last_char>='A')||(last_char<='9'&&last_char>='0')||last_char=='_'))
90
+ if keyword.include?(".h") && line.include?("import") && line.include?("/"+keyword+">")
91
+ dependence_library_name = line[line.index("<")+1...line.index("/"+keyword+">")]
92
+ if dependence_library_name == library_name
93
+ tip = " [file]:"+File.basename(file_path)+" [line]: "+line.strip+" [keyword]: "+keyword
94
+ is_dependence = true
95
+ break
96
+ end
97
+ else
98
+ tip = " [file]:"+File.basename(file_path)+" [line]: "+line.strip+" [keyword]: "+keyword
99
+ is_dependence = true
100
+ break
101
+ end
102
+ end
103
+ end
104
+ end
105
+ if is_dependence
106
+ @spec_library[@spec_library.size] = library_name+tip
107
+ library_keywords_hash.delete(library_name)
108
+ end
109
+ }
110
+
111
+ }
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,27 @@
1
+ module BigKeeper
2
+ module OperateType
3
+ START = 1
4
+ UPDATE = 2
5
+ SWITCH = 3
6
+
7
+ def self.name(type)
8
+ if START == type
9
+ "start"
10
+ elsif UPDATE == type
11
+ "update"
12
+ elsif SWITCH == type
13
+ "switch"
14
+ else
15
+ name
16
+ end
17
+ end
18
+ end
19
+
20
+ module ModuleOperateType
21
+ ADD = 1
22
+ DELETE = 2
23
+ FINISH = 3
24
+ PUBLISH = 4
25
+ RELEASE = 5
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module BigKeeper
3
+
4
+ class PodfileModel
5
+ attr_accessor :name, :git, :path, :configurations, :branch,:tag, :comment
6
+ def initialize(sentence)
7
+ if sentence.include?('#')
8
+ list = sentence.split('#')
9
+ @comment = list[1]
10
+ sentence = list[0]
11
+ end
12
+
13
+ sentence_slip_list = sentence.split(',')
14
+ return if sentence_slip_list.size.zero?
15
+ for piece in sentence_slip_list do
16
+ if /:git =>/ =~ piece
17
+ @git = $~.post_match.strip
18
+ elsif /:path =>/ =~ piece
19
+ @path = $~.post_match.strip
20
+ elsif /:configurations =>/ =~ piece
21
+ @configurations = $~.post_match.strip
22
+ elsif /:branch =>/ =~ piece
23
+ @branch = $~.post_match.strip
24
+ elsif /:tag =>/ =~ piece
25
+ @tag = $~.post_match.strip
26
+ elsif /pod /=~ piece
27
+ @name = $~.post_match.delete("'\n ")
28
+ end
29
+ # p %Q{model name:#{@name},git:#{@git},path:#{@path},config:#{@configurations},branch:#{@branch},tag:#{@tag},comment:#{@comment}}
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,261 @@
1
+ require 'big_keeper/util/git_operator'
2
+ require 'big_keeper/util/gitflow_operator'
3
+ require 'big_keeper/model/gitflow_type'
4
+ require 'big_keeper/model/operate_type'
5
+ require 'big_keeper/util/logger'
6
+
7
+ module BigKeeper
8
+ # Operator for got
9
+ class GitService
10
+
11
+ def startHome(path, name, type)
12
+ p "--------------------11.1.startHome"
13
+ git = GitOperator.new
14
+ branch_name = "#{GitflowType.name(type)}/#{name}"
15
+ p "--------------------11.2branch_name:#{branch_name}"
16
+ if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
17
+ p "------------------------------11.2.1如果远程和本地没有#{branch_name}分支"
18
+ verify_special_branch(path, 'master')
19
+
20
+
21
+ #verify_special_branch(path, 'develop')
22
+
23
+ #GitflowOperator.new.verify_git_flow(path)
24
+
25
+ #GitflowOperator.new.start(path, name, type)
26
+ #
27
+ Dir.chdir(path) do
28
+ p "------------------------------11.2.2git checkout -b #{branch_name}"
29
+ `git checkout -b #{branch_name}`
30
+ end
31
+ git.push_to_remote(path, branch_name)
32
+ else
33
+ verify_checkout(path, branch_name)
34
+
35
+ if !git.has_remote_branch(path, branch_name)
36
+ p "------------------------------11.3.1如果远程没有 #{branch_name}"
37
+ git.push_to_remote(path, branch_name)
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+ def start(path, name, type)
44
+ git = GitOperator.new
45
+
46
+ branch_name = "#{GitflowType.name(type)}/#{name}"
47
+ if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
48
+
49
+ verify_special_branch(path, 'master')
50
+ #verify_special_branch(path, 'develop')
51
+
52
+ #GitflowOperator.new.verify_git_flow(path)
53
+
54
+ #GitflowOperator.new.start(path, name, type)
55
+
56
+ verify_checkout(path, branch_name)
57
+ git.push_to_remote(path, branch_name)
58
+ else
59
+ verify_checkout(path, branch_name)
60
+
61
+ if !git.has_remote_branch(path, branch_name)
62
+ git.push_to_remote(path, branch_name)
63
+ end
64
+ end
65
+ end
66
+
67
+ def verify_checkout(path, branch_name)
68
+ p "++++++++++verify_checkout:#{path} #{branch_name}"
69
+ Dir.chdir(path) do
70
+ p "++++++++++cd:#{path}"
71
+ cmd = "git checkout -b #{branch_name}"
72
+ if GitOperator.new.has_branch(path, branch_name)
73
+ p "++++++++++有#{branch_name}"
74
+ cmd = "git checkout #{branch_name}"
75
+ end
76
+ p "++++++++++cmd:#{cmd}"
77
+ IO.popen(cmd) do |io|
78
+ io.each do |line|
79
+ Logger.error("Checkout #{branch_name} failed.") if line.include? 'error'
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def verify_checkout_pull(path, branch_name)
86
+ GitService.new.verify_checkout(path, branch_name)
87
+ GitService.new.pull(path, branch_name)
88
+ end
89
+
90
+ def verify_special_branch(path, name)
91
+ git = GitOperator.new
92
+ p "----------检查#{name}分支"
93
+ if git.has_remote_branch(path, name)
94
+ p "--------------------有远程#{name}分支"
95
+ if git.has_local_branch(path, name)
96
+ p "------------------------------有本地#{name}分支"
97
+ if git.has_commits(path, name)
98
+ p "----------------------------------------有commits"
99
+ Logger.error(%Q('#{name}' has unpushed commits, you should fix it manually...))
100
+ end
101
+ p "------------------------------git pull"
102
+ git.checkout(path, name)
103
+ pull(path, name)
104
+ else
105
+ p "------------------------------没有本地#{name}分支"
106
+ git.checkout(path, name)
107
+ end
108
+ else
109
+ p "--------------------没有远程#{name}分支"
110
+ verify_checkout(path, name)
111
+ git.push_to_remote(path, name)
112
+ end
113
+ end
114
+
115
+ def verify_home_branch(path, branch_name, type)
116
+
117
+ p "--------------------7.1.从远程同步本地分支"
118
+ Logger.highlight('Sync local branchs from remote, waiting...')
119
+ git = GitOperator.new
120
+ p "--------------------7.2.git fetch origin"
121
+ git.fetch(path)
122
+
123
+ if OperateType::START == type
124
+ if git.current_branch(path) == branch_name
125
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
126
+ end
127
+ if git.has_branch(path, branch_name)
128
+ Logger.error(%(Branch '#{branch_name}' already exists. Use 'switch' please))
129
+ end
130
+ elsif OperateType::SWITCH == type
131
+ if !git.has_branch(path, branch_name)
132
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
133
+ end
134
+ if git.current_branch(path) == branch_name
135
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
136
+ end
137
+ elsif OperateType::UPDATE == type
138
+ if !git.has_branch(path, branch_name)
139
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
140
+ end
141
+ if git.current_branch(path) != branch_name
142
+ Logger.error(%(Current branch is not '#{branch_name}'. Use 'switch' please))
143
+ end
144
+ else
145
+ Logger.error(%(Not a valid command for '#{branch_name}'.))
146
+ end
147
+ end
148
+
149
+ def current_branch_type(path)
150
+ branch_name = GitOperator.new.current_branch(path)
151
+ if branch_name =~ /^feature\/S*/
152
+ GitflowType::FEATURE
153
+ elsif branch_name =~ /^hotfix\/S*/
154
+ GitflowType::HOTFIX
155
+ elsif branch_name =~ /^release\/S*/
156
+ GitflowType::RELEASE
157
+ else
158
+ GitflowType::FEATURE
159
+ end
160
+ end
161
+
162
+ def branchs_with_type(path, type)
163
+ branchs = []
164
+ Dir.chdir(path) do
165
+ IO.popen('git branch -r') do | io |
166
+ io.each do | line |
167
+ branchs << line.gsub(/\s/, '') if line =~ /[\s\S]*#{GitflowType.name(type)}*/
168
+ end
169
+ end
170
+ end
171
+ branchs
172
+ end
173
+
174
+ def pull(path, branch_name)
175
+ git = GitOperator.new
176
+ current_branch_name = git.current_branch(path)
177
+
178
+ p "----------current_branch_name:#{current_branch_name}"
179
+ p "----------branch_name:#{branch_name}"
180
+ if current_branch_name == branch_name
181
+ git.pull(path)
182
+ else
183
+ git.checkout(path, branch_name)
184
+ git.pull(path)
185
+ git.checkout(path, current_branch_name)
186
+ end
187
+ end
188
+
189
+ def verify_del(path, branch_name, name, type)
190
+ git = GitOperator.new
191
+
192
+ if git.has_local_branch(path, branch_name)
193
+ Logger.highlight("Delete local branch '#{branch_name}' for '#{name}'...")
194
+
195
+ if git.current_branch(path) == branch_name
196
+ git.discard(path)
197
+ git.checkout(path, GitflowType.base_branch(type))
198
+ end
199
+ git.del_local(path, branch_name)
200
+ end
201
+
202
+ if git.has_remote_branch(path, branch_name)
203
+ Logger.highlight("Delete remote branch '#{branch_name}' for '#{name}'...")
204
+ git.del_remote(path, branch_name)
205
+ end
206
+ end
207
+
208
+ def verify_push(path, comment, branch_name, name)
209
+ git = GitOperator.new
210
+ if git.has_changes(path) || git.has_commits(path, branch_name)
211
+
212
+ git.commit(path, comment) if git.has_changes(path)
213
+
214
+ if git.has_remote_branch(path, branch_name)
215
+ Dir.chdir(path) do
216
+ `git push`
217
+ end
218
+ else
219
+ git.push_to_remote(path, branch_name)
220
+ end
221
+
222
+ GitOperator.new.check_push_success(path, branch_name, "origin/#{branch_name}")
223
+ else
224
+ Logger.default("Nothing to push for '#{name}'.")
225
+ end
226
+ end
227
+
228
+ def verify_rebase(path, branch_name, name)
229
+
230
+ # pull rebased branch
231
+ pull(path, branch_name)
232
+
233
+ Dir.chdir(path) do
234
+ IO.popen("git rebase #{branch_name} --ignore-whitespace") do |io|
235
+ unless io.gets
236
+ Logger.error("#{name} is already in a rebase-apply, Please:\n"\
237
+ " 1.Resolve it;\n"\
238
+ " 2.Commit the changes;\n"\
239
+ " 3.Push to remote;\n"\
240
+ " 4.Create a MR;\n"\
241
+ " 5.Run 'finish' again.")
242
+ end
243
+ io.each do |line|
244
+ next unless line.include? 'Merge conflict'
245
+ Logger.error("Merge conflict in #{name}, Please:\n"\
246
+ " 1.Resolve it;\n"\
247
+ " 2.Commit the changes;\n"\
248
+ " 3.Push to remote;\n"\
249
+ " 4.Create a MR;\n"\
250
+ " 5.Run 'finish' again.")
251
+ end
252
+ end
253
+ if GitOperator.new.current_branch(path) != 'develop' && GitOperator.new.current_branch(path) != 'master'
254
+ `git push -f`
255
+ else
256
+ Logger.error("You should not push 'master' or 'develop'")
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,161 @@
1
+ require 'big_keeper/service/git_service'
2
+
3
+ require 'big_keeper/util/logger'
4
+ require 'big_keeper/util/cache_operator'
5
+
6
+ module BigKeeper
7
+ # Operator for got
8
+ class ModuleService
9
+
10
+ def verify_module(path, user, module_name, home_branch_name, type)
11
+ name = home_branch_name.gsub(/#{GitflowType.name(type)}\//, '')
12
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
13
+
14
+ git = GitOperator.new
15
+ if !File.exist? module_full_path
16
+ Logger.default("No local repository for module '#{module_name}', clone it...")
17
+ module_git = BigkeeperParser.module_git(module_name)
18
+ git.clone(File.expand_path("#{module_full_path}/../"), module_git)
19
+ end
20
+
21
+ current_branch_name = git.current_branch(module_full_path)
22
+ if current_branch_name != home_branch_name
23
+ # stash current branch
24
+ StashService.new.stash(module_full_path, current_branch_name, module_name)
25
+
26
+ GitService.new.start(module_full_path, name, type)
27
+
28
+ StashService.new.pop_stash(module_full_path, home_branch_name, module_name)
29
+ end
30
+
31
+ StashService.new.pop_stash(module_full_path, home_branch_name, module_name)
32
+ end
33
+
34
+ def push(path, user, module_name, home_branch_name, type, comment)
35
+ Logger.highlight("Push branch '#{home_branch_name}' for module '#{module_name}'...")
36
+
37
+ verify_module(path, user, module_name, home_branch_name, type)
38
+
39
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
40
+ GitService.new.verify_push(module_full_path, comment, home_branch_name, module_name)
41
+ end
42
+
43
+ def rebase(path, user, module_name, home_branch_name, type)
44
+ Logger.highlight("Rebase '#{GitflowType.base_branch(type)}' "\
45
+ "to branch '#{home_branch_name}' for module "\
46
+ "'#{module_name}'...")
47
+
48
+ verify_module(path, user, module_name, home_branch_name, type)
49
+
50
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
51
+
52
+ Logger.error("You have some changes in branch "\
53
+ "'#{home_branch_name}' for module '#{module_name}'. "\
54
+ "Use 'push' first please") if GitOperator.new.has_changes(module_full_path)
55
+
56
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
57
+ end
58
+
59
+ def pull(path, user, module_name, home_branch_name, type)
60
+ Logger.highlight("Pull branch '#{home_branch_name}' for module '#{module_name}'...")
61
+
62
+ verify_module(path, user, module_name, home_branch_name, type)
63
+
64
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
65
+ GitOperator.new.pull(module_full_path)
66
+ end
67
+
68
+ def switch_to(path, user, module_name, home_branch_name, type)
69
+ Logger.highlight("Switch to branch '#{home_branch_name}' for module '#{module_name}'...")
70
+
71
+ verify_module(path, user, module_name, home_branch_name, type)
72
+ end
73
+
74
+ def pre_publish(path, user, module_name, home_branch_name, type)
75
+ Logger.highlight("Prepare to publish branch '#{home_branch_name}' for module '#{module_name}'...")
76
+
77
+ verify_module(path, user, module_name, home_branch_name, type)
78
+
79
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
80
+ GitService.new.verify_push(module_full_path, "prepare to rebase '#{GitflowType.base_branch(type)}'", home_branch_name, module_name)
81
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
82
+ end
83
+
84
+ def publish(path, user, module_name, home_branch_name, type)
85
+ Logger.highlight("Publish branch '#{home_branch_name}' for module '#{module_name}'...")
86
+
87
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::PUBLISH)
88
+
89
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
90
+ GitService.new.verify_push(module_full_path, "publish branch #{home_branch_name}", home_branch_name, module_name)
91
+
92
+ `open #{BigkeeperParser.module_pulls(module_name)}`
93
+
94
+ ModuleCacheOperator.new(path).del_git_module(module_name)
95
+ end
96
+
97
+ def finish(path, user, module_name, home_branch_name, type)
98
+ Logger.highlight("Finish branch '#{home_branch_name}' for module '#{module_name}'...")
99
+
100
+ verify_module(path, user, module_name, home_branch_name, type)
101
+
102
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::FINISH)
103
+
104
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
105
+ GitService.new.verify_push(module_full_path, "finish branch #{home_branch_name}", home_branch_name, module_name)
106
+
107
+ ModuleCacheOperator.new(path).add_git_module(module_name)
108
+ ModuleCacheOperator.new(path).del_path_module(module_name)
109
+ end
110
+
111
+ def add(path, user, module_name, name, type)
112
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
113
+ Logger.highlight("Add branch '#{home_branch_name}' for module '#{module_name}'...")
114
+
115
+ verify_module(path, user, module_name, home_branch_name, type)
116
+
117
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::ADD)
118
+
119
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
120
+ GitService.new.verify_push(module_full_path, "init #{GitflowType.name(type)} #{name}", home_branch_name, module_name)
121
+
122
+ ModuleCacheOperator.new(path).add_path_module(module_name)
123
+ end
124
+
125
+ def del(path, user, module_name, name, type)
126
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
127
+
128
+ Logger.highlight("Delete branch '#{home_branch_name}' for module '#{module_name}'...")
129
+
130
+ module_git = BigkeeperParser.module_git(module_name)
131
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::DELETE)
132
+
133
+ # Stash module current branch
134
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
135
+ current_branch_name = GitOperator.new.current_branch(module_full_path)
136
+ StashService.new.stash(module_full_path, current_branch_name, module_name)
137
+ GitOperator.new.checkout(module_full_path, GitflowType.base_branch(type))
138
+
139
+ ModuleCacheOperator.new(path).del_path_module(module_name)
140
+ end
141
+
142
+ def module_info(module_path, home_branch_name, user, type, module_name, version)
143
+ result_dic = {}
144
+ matched_branches = []
145
+ branches = GitService.new.branchs_with_type(module_path, type)
146
+ if version == 'all versions'
147
+ matched_branches = branches
148
+ else
149
+ branches.each do | branch |
150
+ matched_branches << branch if branch.include?(version)
151
+ end
152
+ end
153
+ result_dic[:module_name] = module_name
154
+ result_dic[:current_branch] = GitOperator.new.current_branch(module_path)
155
+ result_dic[:branches] = matched_branches
156
+ result_dic
157
+ end
158
+
159
+ private :verify_module
160
+ end
161
+ end