brightpearl-cli 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/brightpearl_cli.rb +151 -76
- data/lib/core/config.rb +67 -17
- data/lib/core/encrypter.rb +55 -0
- data/lib/core/enums.rb +2 -0
- data/lib/core/git.rb +82 -37
- data/lib/core/mysql.rb +34 -8
- data/lib/core/terminal.rb +74 -165
- data/lib/core/tools.rb +33 -13
- data/lib/routes/build.rb +92 -19
- data/lib/routes/git_checkout.rb +13 -19
- data/lib/routes/git_delete.rb +18 -33
- data/lib/routes/git_merge.rb +148 -70
- data/lib/routes/git_pull.rb +40 -4
- data/lib/routes/git_push.rb +40 -4
- data/lib/routes/git_stash.rb +19 -2
- data/lib/routes/git_update.rb +13 -73
- data/lib/routes/jira.rb +1 -0
- data/lib/routes/production_logs.rb +356 -0
- data/lib/routes/review.rb +30 -4
- data/lib/routes/scripts_api_docs.rb +41 -0
- data/lib/routes/scripts_branch_cleaner.rb +196 -0
- data/lib/routes/scripts_pom_fixer.rb +94 -0
- data/lib/routes/setup.rb +11 -3
- data/lib/routes/tail.rb +46 -0
- metadata +15 -10
- data/lib/routes/less.rb +0 -37
- /data/lib/routes/{tests.rb → test.rb} +0 -0
data/lib/routes/git_merge.rb
CHANGED
@@ -18,8 +18,12 @@ module BrightpearlCommand
|
|
18
18
|
|
19
19
|
def opts_validate
|
20
20
|
|
21
|
+
if @opts[:from_file] && @opts[:open_file]
|
22
|
+
Brightpearl::Terminal::error('Too many flags', "You cannot pass the #{Brightpearl::Terminal::format_flag('o', false)} and #{Brightpearl::Terminal::format_flag('f', false)} flags at the same time.", true)
|
23
|
+
end
|
24
|
+
|
21
25
|
unless @args.any?
|
22
|
-
unless @opts[:from_file]
|
26
|
+
unless @opts[:from_file] || @opts[:open_file]
|
23
27
|
system('bp g m -h')
|
24
28
|
exit
|
25
29
|
end
|
@@ -31,10 +35,12 @@ module BrightpearlCommand
|
|
31
35
|
|
32
36
|
if @opts[:from_file]
|
33
37
|
unless @args[1].nil?
|
34
|
-
Brightpearl::Terminal::error('Too many parameters', ["When using the #{Brightpearl::Terminal::format_flag('f')}\x1B[38;5;240m
|
38
|
+
Brightpearl::Terminal::error('Too many parameters', ["When using the #{Brightpearl::Terminal::format_flag('f')}\x1B[38;5;240m the system only expects one #{Brightpearl::Terminal::format_action('optional')}\x1B[38;5;240m parameter \xe2\x80\x94 the target branch.", "The amount of parameters you passed were: #{Brightpearl::Terminal::format_highlight(@args.length)}"], true)
|
35
39
|
end
|
36
|
-
|
37
|
-
Brightpearl::Terminal::error(
|
40
|
+
if @opts[:from_file] != '' && File.file?(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE) == false
|
41
|
+
Brightpearl::Terminal::error("File not found: #{Brightpearl::Terminal::format_directory(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE)}", [
|
42
|
+
"To specify multiple #{Brightpearl::Terminal::format_branch('source-branches')} try running #{Brightpearl::Terminal::format_command('bp g m -o')} first."
|
43
|
+
], true)
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
@@ -42,6 +48,11 @@ module BrightpearlCommand
|
|
42
48
|
|
43
49
|
def opts_routing
|
44
50
|
|
51
|
+
if @opts[:open_file]
|
52
|
+
system("#{Brightpearl::Config.param(Brightpearl::Config::PREFERRED_TEXT_EDITOR)} #{Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE}")
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
45
56
|
retrieve_source_branches
|
46
57
|
retrieve_target_branches
|
47
58
|
|
@@ -51,9 +62,32 @@ module BrightpearlCommand
|
|
51
62
|
|
52
63
|
def merge
|
53
64
|
|
54
|
-
|
65
|
+
@git.check_for_uncommitted_files(false, 'Aborting the merge!')
|
66
|
+
|
67
|
+
# If no 'source branches' are found, select current branch (if both repos on same branch) or throw Error.
|
68
|
+
unless @source_branches.any?
|
69
|
+
code_sb = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
70
|
+
db_sb = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))
|
71
|
+
if code_sb != db_sb
|
72
|
+
Brightpearl::Terminal::error('Cannot reliably determine source branch', ["You're repos are on two different branches:", nil, "Code \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(code_sb)}", " DB \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(db_sb)}", nil, 'In this particular scenario, you must explicitly specify a source branch in order to merge.'], true)
|
73
|
+
end
|
74
|
+
@source_branches << code_sb
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check MASTER isn't one of the 'source branches'
|
78
|
+
@source_branches.each do |branch|
|
79
|
+
if branch == Brightpearl::Git::MASTER
|
80
|
+
Brightpearl::Terminal::error("#{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} has been recognized as a #{Brightpearl::Terminal::format_highlight('source branch')}", ["If your intention is to merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} into #{Brightpearl::Terminal::format_branch(@target_branch)}, use #{Brightpearl::Terminal::format_command('bp g u')} instead."], true)
|
81
|
+
end
|
82
|
+
end
|
55
83
|
|
56
|
-
|
84
|
+
# Check a RELEASE-BRANCH isn't one of the 'target branches'
|
85
|
+
if @target_branch =~ Brightpearl::Git::RELEASE_BRANCH_REGEX
|
86
|
+
Brightpearl::Terminal::error("#{Brightpearl::Terminal::format_branch(@target_branch)} has been recognized as a #{Brightpearl::Terminal::format_highlight('target branch')}", ["You #{Brightpearl::Terminal::format_invalid('cannot use this script', true)} to merge to a release branch.", "It's usually best to do this manually."], true)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Initial confirmation
|
90
|
+
unless Brightpearl::Terminal::prompt_yes_no("You're about to #{Brightpearl::Terminal::format_action('initiate a merge')} between the following branch(es):", generate_source_target_text, "Would you like to #{Brightpearl::Terminal::format_action('CONTINUE')}\x1B[38;5;89m")
|
57
91
|
Brightpearl::Terminal::abort(nil, nil, true, false)
|
58
92
|
end
|
59
93
|
|
@@ -67,25 +101,27 @@ module BrightpearlCommand
|
|
67
101
|
non_existent_branches_db = []
|
68
102
|
branches_with_stashes_cd = []
|
69
103
|
branches_with_stashes_db = []
|
70
|
-
|
71
|
-
|
72
|
-
# # SANITY CHECK SCRIPT
|
73
|
-
# @source_branches.each do |x|
|
74
|
-
# grep_string = x.split('-')
|
75
|
-
# grep_string = "BP-#{grep_string[grep_string.count - 1]}"
|
76
|
-
# puts "\x1B[38;5;39m#{x}\x1B[0m \xe2\x80\x94 (#{grep_string})"
|
77
|
-
# system("cd #{Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)} && git log | grep '#{grep_string}' --color=auto")
|
78
|
-
# system("cd #{Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)} && git log | grep '#{grep_string}' --color=auto")
|
79
|
-
# end
|
80
|
-
# puts
|
81
|
-
# exit
|
104
|
+
changed_files_code = {}
|
105
|
+
changed_files_db = {}
|
82
106
|
|
83
107
|
# UPDATE MASTER & CHECKOUT BRANCH TO MERGE TO
|
84
108
|
Brightpearl::Terminal::output("Updating #{Brightpearl::Terminal::format_branch(@target_branch)}")
|
85
109
|
target_branch_data = @git.branch_data(@target_branch, nil, false)
|
86
|
-
if target_branch_data[0][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
|
110
|
+
if target_branch_data[0][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false && target_branch_data[1][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
|
87
111
|
Brightpearl::Terminal::error("Target branch #{Brightpearl::Terminal::format_branch(@target_branch)} doesn't exist", 'Please check your spelling and try again.', true)
|
88
112
|
end
|
113
|
+
|
114
|
+
# CREATE TARGET BRANCH (CODE OR DB) IF ONE OR THE OTHER DOESN'T EXIST
|
115
|
+
if target_branch_data[0][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
|
116
|
+
Brightpearl::Terminal::warning("Target #{Brightpearl::Terminal::format_highlight('CODE')} branch doesn't exist")
|
117
|
+
Brightpearl::Terminal::output("Creating branch #{Brightpearl::Terminal::format_branch(@target_branch)} in #{Brightpearl::Terminal::format_directory(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))}")
|
118
|
+
Brightpearl::Terminal::error('Not yet implemented', ["The code which should create branch #{Brightpearl::Terminal::format_branch(@target_branch)} on #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))} hasn't been programmed yet.", "Please speak to #{Brightpearl::Terminal::format_highlight('Albert')}."], true)
|
119
|
+
elsif target_branch_data[1][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
|
120
|
+
Brightpearl::Terminal::warning("Target #{Brightpearl::Terminal::format_highlight('DB')} branch doesn't exist")
|
121
|
+
Brightpearl::Terminal::output("Creating branch #{Brightpearl::Terminal::format_branch(@target_branch)} in #{Brightpearl::Terminal::format_directory(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))}")
|
122
|
+
Brightpearl::Terminal::error('Not yet implemented', ["The code which should create branch #{Brightpearl::Terminal::format_branch(@target_branch)} on #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))} hasn't been programmed yet.", "Please speak to #{Brightpearl::Terminal::format_highlight('Albert')}."], true)
|
123
|
+
end
|
124
|
+
|
89
125
|
commands = [
|
90
126
|
"git checkout #{Brightpearl::Git::MASTER}",
|
91
127
|
'git pull',
|
@@ -103,7 +139,7 @@ module BrightpearlCommand
|
|
103
139
|
branches_data << @git.branch_data(branch_name, nil, false)
|
104
140
|
end
|
105
141
|
|
106
|
-
# RUN CHECKS
|
142
|
+
# RUN CHECKS (AND CHECKOUT BRANCHES WHICH DON'T EXIST LOCALLY)
|
107
143
|
branches_data.each do |branch_data|
|
108
144
|
if branch_data[0][:"#{Brightpearl::Git::BRANCH_EXISTS}"] || branch_data[1][:"#{Brightpearl::Git::BRANCH_EXISTS}"]
|
109
145
|
atleast_one_branch_found = true
|
@@ -140,96 +176,128 @@ module BrightpearlCommand
|
|
140
176
|
|
141
177
|
puts # DO NOT REMOVE.
|
142
178
|
|
143
|
-
|
179
|
+
if non_existent_branches_cd.any? || branches_with_stashes_cd.any?
|
180
|
+
puts "\n #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))}\n\n"
|
181
|
+
end
|
144
182
|
if non_existent_branches_cd.any?
|
145
|
-
Brightpearl::Terminal::warning("The following branches could not be found
|
183
|
+
Brightpearl::Terminal::warning("The following branches #{Brightpearl::Terminal::format_invalid('could not be found', true)} \xe2\x80\x94 #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))}", non_existent_branches_cd, false)
|
146
184
|
atleast_one_error = true
|
147
185
|
end
|
148
|
-
if
|
149
|
-
Brightpearl::Terminal::warning("The following branches
|
186
|
+
if branches_with_stashes_cd.any?
|
187
|
+
Brightpearl::Terminal::warning("The following branches #{Brightpearl::Terminal::format_invalid('have stashes', true)} \xe2\x80\x94 #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))}", branches_with_stashes_cd, false)
|
150
188
|
atleast_one_error = true
|
151
189
|
end
|
152
|
-
if
|
153
|
-
Brightpearl::Terminal::
|
190
|
+
if non_existent_branches_db.any? || branches_with_stashes_db.any?
|
191
|
+
puts "\n #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))}\n\n"
|
192
|
+
end
|
193
|
+
if non_existent_branches_db.any?
|
194
|
+
Brightpearl::Terminal::warning("The following branches #{Brightpearl::Terminal::format_invalid('could not be found', true)} \xe2\x80\x94 #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))}", non_existent_branches_db, false)
|
154
195
|
atleast_one_error = true
|
155
196
|
end
|
156
197
|
if branches_with_stashes_db.any?
|
157
|
-
Brightpearl::Terminal::
|
198
|
+
Brightpearl::Terminal::warning("The following branches #{Brightpearl::Terminal::format_invalid('have stashes', true)} \xe2\x80\x94 #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))}", branches_with_stashes_db, false)
|
158
199
|
atleast_one_error = true
|
159
200
|
end
|
160
201
|
if atleast_one_branch_found == false
|
161
|
-
Brightpearl::Terminal::error('
|
202
|
+
Brightpearl::Terminal::error('Source branches not found', 'Nothing to merge. Aborting script.', true)
|
162
203
|
end
|
163
204
|
|
164
|
-
|
205
|
+
non_existent_branches_cd_dup = non_existent_branches_cd.dup
|
206
|
+
non_existent_branches_db_dup = non_existent_branches_db.dup
|
207
|
+
|
208
|
+
source_target_text = generate_source_target_text(non_existent_branches_cd_dup.concat(non_existent_branches_db_dup).uniq!)
|
165
209
|
source_target_text.unshift('')
|
166
210
|
if atleast_one_error
|
167
211
|
source_target_text.unshift('Although issues were detected, the script determined that these are non-fatal and can continue with the merge.')
|
168
212
|
end
|
169
213
|
source_target_text.unshift("This is officially the \x1B[38;5;196mPOINT OF NO RETURN\x1B[38;5;240m. Please make sure everything is OK before continuing.")
|
170
214
|
|
171
|
-
unless Brightpearl::Terminal::prompt_yes_no("You're about to #{Brightpearl::Terminal::format_action('merge')}
|
215
|
+
unless Brightpearl::Terminal::prompt_yes_no("You're about to #{Brightpearl::Terminal::format_action('merge')} between following branch(es):", source_target_text, "Are you absolutely sure you would like to #{Brightpearl::Terminal::format_action('CONTINUE')}\x1B[38;5;89m with the merge?")
|
172
216
|
Brightpearl::Terminal::abort(nil, nil, true, false)
|
173
217
|
end
|
174
218
|
|
175
|
-
#
|
219
|
+
# MERGE STARTS HERE !!
|
176
220
|
branches_data.each do |branch_data|
|
177
221
|
|
178
222
|
branch_name = branch_data[0][:"#{Brightpearl::Git::BRANCH_NAME}"]
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
223
|
+
commands_1 = [
|
224
|
+
"git checkout #{branch_name}"
|
225
|
+
]
|
226
|
+
commands_2 = [
|
227
|
+
"git merge #{Brightpearl::Git::MASTER}"
|
228
|
+
]
|
229
|
+
commands_3 = [
|
230
|
+
"git diff --name-only #{Brightpearl::Git::MASTER}"
|
231
|
+
]
|
232
|
+
commands_4 = [
|
184
233
|
'git push',
|
185
234
|
"git checkout #{@target_branch}"
|
186
235
|
]
|
187
|
-
|
236
|
+
commands_5 = [
|
237
|
+
"git merge #{branch_name}",
|
238
|
+
]
|
239
|
+
commands_6 = []
|
240
|
+
if @target_branch != Brightpearl::Git::MASTER
|
241
|
+
commands_6 << 'git push'
|
242
|
+
end
|
188
243
|
|
189
244
|
# CODE BRANCHES
|
190
245
|
unless non_existent_branches_cd.include?(branch_name)
|
191
|
-
Brightpearl::Terminal::command(
|
192
|
-
|
246
|
+
Brightpearl::Terminal::command(commands_1, cd_repo)
|
247
|
+
Brightpearl::Terminal::command('git pull', cd_repo) if branch_data[0][:"#{Brightpearl::Git::BRANCH_HAS_UPSTREAM}"]
|
248
|
+
merge_master_result = Brightpearl::Terminal::command(commands_2, cd_repo)
|
193
249
|
if merge_master_result[0] == false
|
194
|
-
Brightpearl::Terminal::error('Merge conflict occurred', "Unable to successfully merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))})", true)
|
250
|
+
Brightpearl::Terminal::error('Merge conflict occurred', "Unable to successfully merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))})", true)
|
251
|
+
end
|
252
|
+
changed_files_code["#{branch_name}"] = Brightpearl::Terminal::command_capture(commands_3, cd_repo)
|
253
|
+
Brightpearl::Terminal::command(commands_4, cd_repo)
|
254
|
+
merge_to_target = Brightpearl::Terminal::command(commands_5, cd_repo)
|
255
|
+
if merge_to_target[0] == false
|
256
|
+
Brightpearl::Terminal::error('Merge conflict occurred', ["Unable to successfully merge #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))})", "Please #{Brightpearl::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing."], true)
|
195
257
|
end
|
196
|
-
|
197
|
-
|
198
|
-
if merge_to_target == false
|
199
|
-
Brightpearl::Terminal::error('Merge conflict occurred', "Unable to successfully merge #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))})", true)
|
258
|
+
if commands_6.any?
|
259
|
+
Brightpearl::Terminal::command(commands_6, cd_repo)
|
200
260
|
end
|
201
261
|
end
|
202
262
|
|
203
263
|
# DB BRANCHES
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
Brightpearl::Terminal::command(
|
208
|
-
merge_master_result = Brightpearl::Terminal::command(commands2, db_repo)
|
264
|
+
unless non_existent_branches_db.include?(branch_name)
|
265
|
+
Brightpearl::Terminal::command(commands_1, db_repo)
|
266
|
+
Brightpearl::Terminal::command('git pull', db_repo) if branch_data[1][:"#{Brightpearl::Git::BRANCH_HAS_UPSTREAM}"]
|
267
|
+
merge_master_result = Brightpearl::Terminal::command(commands_2, db_repo)
|
209
268
|
if merge_master_result[0] == false
|
210
|
-
Brightpearl::Terminal::error('Merge conflict occurred', "Unable to successfully merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))})", true)
|
269
|
+
Brightpearl::Terminal::error('Merge conflict occurred', ["Unable to successfully merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))})", "Please #{Brightpearl::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing."], true)
|
270
|
+
end
|
271
|
+
changed_files_db["#{branch_name}"] = Brightpearl::Terminal::command_capture(commands_3, db_repo)
|
272
|
+
Brightpearl::Terminal::command(commands_4, db_repo, false)
|
273
|
+
merge_to_target = Brightpearl::Terminal::command(commands_5, db_repo)
|
274
|
+
if merge_to_target[0] == false
|
275
|
+
Brightpearl::Terminal::error('Merge conflict occurred', ["Unable to successfully merge #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))})", "Please #{Brightpearl::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing."], true)
|
211
276
|
end
|
212
|
-
|
213
|
-
|
214
|
-
if merge_to_target == false
|
215
|
-
Brightpearl::Terminal::error('Merge conflict occurred', "Unable to successfully merge #{Brightpearl::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))})", true)
|
277
|
+
if commands_6.any?
|
278
|
+
Brightpearl::Terminal::command(commands_6, db_repo)
|
216
279
|
end
|
217
280
|
end
|
218
281
|
|
219
282
|
end
|
220
283
|
|
221
284
|
Brightpearl::Terminal::success('It seems as if everything ran smoothly', "#{@source_branches.count} #{(@source_branches.count) == 1 ? 'branch has' : 'branches have'} been successfully merged to #{Brightpearl::Terminal::format_branch(@target_branch)}")
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
285
|
+
|
286
|
+
if Brightpearl::Config.param(Brightpearl::Config::BETA)
|
287
|
+
|
288
|
+
if Brightpearl::Terminal::prompt_yes_no('Just to be safe, would you like to run a sanity check?', ["This will execute #{Brightpearl::Terminal::format_command('git log')}\x1B[38;5;240m on #{Brightpearl::Terminal::format_branch(@target_branch)}\x1B[38;5;240m and #{Brightpearl::Terminal::format_command('grep')}\x1B[38;5;240m for Jira numbers relating all the branches you have just merged. This way we can double-check they have actually been merged.", nil, "Please note this process may not be \x1B[38;5;250m100%\x1B[38;5;240m reliable."])
|
289
|
+
|
290
|
+
# SANITY CHECK SCRIPT
|
291
|
+
@source_branches.each do |x|
|
292
|
+
grep_string = x.split('-')
|
293
|
+
grep_string = "BP-#{grep_string[grep_string.count - 1]}"
|
294
|
+
puts "\x1B[38;5;39m#{x}\x1B[0m \xe2\x80\x94 (#{grep_string})"
|
295
|
+
system("cd #{Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)} && git log | grep '#{grep_string}' --color=auto")
|
296
|
+
system("cd #{Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)} && git log | grep '#{grep_string}' --color=auto")
|
297
|
+
end
|
298
|
+
puts
|
299
|
+
|
231
300
|
end
|
232
|
-
puts
|
233
301
|
|
234
302
|
end
|
235
303
|
|
@@ -239,7 +307,7 @@ module BrightpearlCommand
|
|
239
307
|
|
240
308
|
def retrieve_source_branches
|
241
309
|
if @opts[:from_file]
|
242
|
-
File.open(
|
310
|
+
File.open(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE).each do |line|
|
243
311
|
line_trimmed = line.gsub(/\s+/, '')
|
244
312
|
if line_trimmed != ''
|
245
313
|
line_split = line_trimmed.split(',')
|
@@ -252,30 +320,40 @@ module BrightpearlCommand
|
|
252
320
|
end
|
253
321
|
@source_branches.sort_by! { |m| m.downcase }
|
254
322
|
@source_branches.uniq!
|
323
|
+
unless @source_branches.any?
|
324
|
+
error_text = nil
|
325
|
+
if @opts[:from_file]
|
326
|
+
error_text = "No source branches found in: #{Brightpearl::Terminal::format_directory(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE)}"
|
327
|
+
end
|
328
|
+
Brightpearl::Terminal::error('Cannot determine source branch(es)', error_text, true)
|
329
|
+
end
|
255
330
|
end
|
256
331
|
|
257
332
|
def retrieve_target_branches
|
258
333
|
if @opts[:from_file]
|
259
334
|
if @args[0].nil?
|
260
|
-
@target_branch = Brightpearl::
|
335
|
+
@target_branch = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
261
336
|
else
|
262
337
|
@target_branch = @args[0]
|
263
338
|
end
|
264
339
|
else
|
265
340
|
if @args[1].nil?
|
266
|
-
@target_branch = Brightpearl::
|
341
|
+
@target_branch = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
267
342
|
else
|
268
343
|
@target_branch = @args[1]
|
269
344
|
end
|
270
345
|
end
|
271
346
|
end
|
272
347
|
|
273
|
-
def generate_source_target_text
|
348
|
+
def generate_source_target_text(branches_with_issues = nil)
|
349
|
+
branches_with_issues = [] if branches_with_issues.nil?
|
274
350
|
source_branches_dup = @source_branches.dup
|
275
|
-
|
351
|
+
first_branch_color = (branches_with_issues.include?(source_branches_dup[0])) ? '240' : '117'
|
352
|
+
source_branch_text = ["Source branch(es): \x1B[38;5;#{first_branch_color}m#{source_branches_dup.shift}"]
|
276
353
|
unless source_branches_dup.empty?
|
277
354
|
source_branches_dup.each do |sb|
|
278
|
-
|
355
|
+
branch_color = (branches_with_issues.include?(sb)) ? '240' : '117'
|
356
|
+
source_branch_text << " \x1B[38;5;#{branch_color}m#{sb}"
|
279
357
|
end
|
280
358
|
source_branch_text << ''
|
281
359
|
end
|
data/lib/routes/git_pull.rb
CHANGED
@@ -4,10 +4,46 @@ module BrightpearlCommand
|
|
4
4
|
|
5
5
|
def execute
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
@opts = command_options
|
8
|
+
@args = arguments
|
9
|
+
@git = Brightpearl::Git.new
|
10
|
+
|
11
|
+
opts_validate
|
12
|
+
opts_routing
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def opts_validate
|
17
|
+
|
18
|
+
if @args[0].nil?
|
19
|
+
@args[0] = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def opts_routing
|
25
|
+
|
26
|
+
git_pull
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def git_pull
|
31
|
+
|
32
|
+
@git.check_for_same_branch(Brightpearl::Git::SAME_BRANCH_WARNING)
|
33
|
+
branch_code = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
34
|
+
branch_db = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))
|
35
|
+
if Brightpearl::Terminal::prompt_yes_no("#{Brightpearl::Terminal::format_action('pull')} the following repos:", [
|
36
|
+
"#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))} will pull #{Brightpearl::Terminal::format_branch(branch_code)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch("origin/#{branch_code}")}",
|
37
|
+
"#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))} will pull #{Brightpearl::Terminal::format_branch(branch_db)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch("origin/#{branch_db}")}"
|
38
|
+
])
|
39
|
+
@git.check_for_uncommitted_files(true)
|
40
|
+
@git.repo_loop.each do |repo_dir|
|
41
|
+
unless Brightpearl::Terminal::command_capture("git pull origin #{@git.current_branch_for_repo(repo_dir)}", repo_dir)
|
42
|
+
Brightpearl::Terminal::warning('Something went wrong', "Not sure what the reason was, but doing a #{Brightpearl::Terminal::format_command('git pull')} on #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} was unsuccessful.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@git.check_for_stash(true)
|
46
|
+
end
|
11
47
|
|
12
48
|
end
|
13
49
|
|
data/lib/routes/git_push.rb
CHANGED
@@ -4,10 +4,46 @@ module BrightpearlCommand
|
|
4
4
|
|
5
5
|
def execute
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
@opts = command_options
|
8
|
+
@args = arguments
|
9
|
+
@git = Brightpearl::Git.new
|
10
|
+
|
11
|
+
opts_validate
|
12
|
+
opts_routing
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def opts_validate
|
17
|
+
|
18
|
+
if @args[0].nil?
|
19
|
+
@args[0] = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def opts_routing
|
25
|
+
|
26
|
+
git_push
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def git_push
|
31
|
+
|
32
|
+
@git.check_for_same_branch(Brightpearl::Git::SAME_BRANCH_WARNING)
|
33
|
+
branch_code = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
34
|
+
branch_db = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))
|
35
|
+
if Brightpearl::Terminal::prompt_yes_no("#{Brightpearl::Terminal::format_action('push')} the following repos:", [
|
36
|
+
"#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)))} will push #{Brightpearl::Terminal::format_branch(branch_code)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch("origin/#{branch_code}")}",
|
37
|
+
"#{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)))} will push #{Brightpearl::Terminal::format_branch(branch_db)} \xe2\x86\x92 #{Brightpearl::Terminal::format_branch("origin/#{branch_db}")}"
|
38
|
+
])
|
39
|
+
@git.check_for_uncommitted_files(true)
|
40
|
+
@git.repo_loop.each do |repo_dir|
|
41
|
+
unless Brightpearl::Terminal::command_capture("git push origin #{@git.current_branch_for_repo(repo_dir)}", repo_dir)
|
42
|
+
Brightpearl::Terminal::warning('Something went wrong', "Not sure what the reason was, but doing a #{Brightpearl::Terminal::format_command('git push')} on #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} was unsuccessful.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@git.check_for_stash(true)
|
46
|
+
end
|
11
47
|
|
12
48
|
end
|
13
49
|
|
data/lib/routes/git_stash.rb
CHANGED
@@ -6,6 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
+
@git = Brightpearl::Git.new
|
9
10
|
opts_validate
|
10
11
|
opts_routing
|
11
12
|
|
@@ -17,8 +18,24 @@ module BrightpearlCommand
|
|
17
18
|
|
18
19
|
def opts_routing
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
show_all_stashes
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_all_stashes
|
26
|
+
|
27
|
+
@git.repo_loop.each do |repo_dir|
|
28
|
+
stashes = `cd #{repo_dir} && git stash list`
|
29
|
+
stashes = stashes.split("\n")
|
30
|
+
# Skip if no stashes.
|
31
|
+
next unless stashes.any?
|
32
|
+
Brightpearl::Terminal::info("Showing stashes for: #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}")
|
33
|
+
stashes.each do |stash|
|
34
|
+
stash_name = stash.split(/:/).first
|
35
|
+
output = Brightpearl::Terminal::command_capture("git stash show --name-only #{stash_name}", repo_dir, false)
|
36
|
+
Brightpearl::Terminal::info("#{stash}", output[0], false)
|
37
|
+
end
|
38
|
+
end
|
22
39
|
|
23
40
|
end
|
24
41
|
|
data/lib/routes/git_update.rb
CHANGED
@@ -28,8 +28,7 @@ module BrightpearlCommand
|
|
28
28
|
# Updates the current branch.
|
29
29
|
# @return void
|
30
30
|
def update_branch_single
|
31
|
-
|
32
|
-
@git.stash_staged_changes
|
31
|
+
@git.check_for_uncommitted_files(true)
|
33
32
|
@git.repo_loop.each do |repo_dir|
|
34
33
|
current_branch = @git.current_branch_for_repo(repo_dir)
|
35
34
|
commands = Array.new
|
@@ -43,83 +42,24 @@ module BrightpearlCommand
|
|
43
42
|
commands << 'git merge master'
|
44
43
|
end
|
45
44
|
results = Brightpearl::Terminal::command(commands, repo_dir)
|
46
|
-
if
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
if current_branch != Brightpearl::Git::MASTER
|
46
|
+
if results[3] == false
|
47
|
+
@git.ask_to_setup_remote_tracking(current_branch, repo_dir)
|
48
|
+
end
|
49
|
+
if results[4] == false
|
50
|
+
Brightpearl::Terminal::error('Merge conflict occurred', ["Unable to successfully merge #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} into #{Brightpearl::Terminal::format_branch(current_branch)} on #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}", "Please #{Brightpearl::Terminal::format_action('open an IDE')}\x1B[38;5;240m and resolve your conflicts as soon as this script has finished executing."])
|
51
|
+
end
|
50
52
|
end
|
51
|
-
if @opts[:push] &&
|
52
|
-
Brightpearl::Terminal::command(
|
53
|
+
if @opts[:push] && current_branch != Brightpearl::Git::MASTER
|
54
|
+
Brightpearl::Terminal::command("git push origin #{current_branch}", repo_dir)
|
55
|
+
elsif @opts[:push] && current_branch == Brightpearl::Git::MASTER
|
56
|
+
Brightpearl::Terminal::warning("#{Brightpearl::Terminal::format_action('push')} to #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)} not allowed!", ["Your #{Brightpearl::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} repo is currently on #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)}","The script will not perform a #{Brightpearl::Terminal::format_action('push')} as requested for safety reasons."])
|
53
57
|
end
|
54
58
|
|
55
59
|
end
|
56
|
-
|
57
|
-
@git.check_for_stash
|
58
|
-
end
|
60
|
+
@git.check_for_stash(true)
|
59
61
|
end
|
60
62
|
|
61
|
-
# Updates ALL local branches.
|
62
|
-
# @return void
|
63
|
-
# def update_branch_all
|
64
|
-
# Brightpearl::Tools::verify_internet_access
|
65
|
-
# repos = []
|
66
|
-
# brightpearl_code, brightpearl_db = @git.get_branches_as_array(Brightpearl::Git::SORT_REFNAME, Brightpearl::Git::LOCAL)
|
67
|
-
# Array[brightpearl_code, brightpearl_db].each do |repo_data|
|
68
|
-
# branches = []
|
69
|
-
# repo_data.each do |branch_name|
|
70
|
-
# if branch_name[0..6] != Brightpearl::Git::MERGED_PREFIX
|
71
|
-
# branches << branch_name
|
72
|
-
# end
|
73
|
-
# end
|
74
|
-
# repos << branches
|
75
|
-
# end
|
76
|
-
# message = [
|
77
|
-
# "You are about to merge master into ALL of the following branches:\n\n",
|
78
|
-
# "\x1B[33mbrightpearl-code \xe2\x86\x92 \x1B[0m\x1B[32m#{repos[0].join(', ')}\x1B[0m",
|
79
|
-
# "\x1B[33mbrightpearl-db \xe2\x86\x92 \x1B[0m\x1B[32m#{repos[1].join(', ')}\x1B[0m\n\n",
|
80
|
-
# 'This script will pull from master, merge master into ALL of your branches & then push your branches back up to /origin.'
|
81
|
-
# ]
|
82
|
-
# branch_count = repos[0].length + repos[1].length
|
83
|
-
# if (branch_count) > 9
|
84
|
-
# message << "\n\x1B[41m WARNING \x1B[0m You're about to update \x1B[32m#{branch_count}\x1B[0m branches. This could take a while.."
|
85
|
-
# end
|
86
|
-
# Brightpearl::Terminal::prompt_enter(message)
|
87
|
-
#
|
88
|
-
# # Update master on both repos.
|
89
|
-
# @git.repo_loop.each do |repo_dir|
|
90
|
-
# current_branch = @git.current_branch_for_repo(repo_dir)
|
91
|
-
# commands = Array.new
|
92
|
-
# if current_branch != Brightpearl::Git::MASTER
|
93
|
-
# commands << 'git checkout master'
|
94
|
-
# end
|
95
|
-
# commands << 'git pull'
|
96
|
-
# Brightpearl::Terminal::command(commands, repo_dir)
|
97
|
-
# end
|
98
|
-
#
|
99
|
-
# # Update ALL the branches, one-by-one.
|
100
|
-
# repos[0].each do |branch|
|
101
|
-
# update_branch(branch, Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
|
102
|
-
# end
|
103
|
-
# repos[1].each do |branch|
|
104
|
-
# update_branch(branch, Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB))
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# end
|
108
|
-
|
109
|
-
# Updates a single branch.
|
110
|
-
# @return void
|
111
|
-
# def update_branch(branch_name, repo_dir)
|
112
|
-
# if branch_name != Brightpearl::Git::MASTER
|
113
|
-
# puts "\x1B[45m Check-out \x1B[0m \x1B[32m\xe2\x86\x92\x1B[0m \x1B[35m#{branch_name}\x1B[0m"
|
114
|
-
# commands = Array.new
|
115
|
-
# commands << "git checkout #{branch_name}"
|
116
|
-
# # commands << 'git pull'
|
117
|
-
# commands << 'git merge --no-commit --no-ff master | grep CONFLICT'
|
118
|
-
# # commands << 'git push'
|
119
|
-
# Brightpearl::Terminal::command(commands, repo_dir)
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
|
123
63
|
end
|
124
64
|
|
125
65
|
end
|