brightpearl-cli 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/bp +1 -1
- data/bin/brightpearl +1 -1
- data/lib/brightpearl_cli.rb +161 -168
- data/lib/core/api.rb +1 -1
- data/lib/core/config.rb +10 -133
- data/lib/core/config_unique.rb +113 -0
- data/lib/core/encrypter.rb +6 -6
- data/lib/core/enums.rb +1 -1
- data/lib/core/git.rb +123 -108
- data/lib/core/git_delete.rb +89 -0
- data/lib/core/jira.rb +2 -2
- data/lib/core/mysql.rb +14 -14
- data/lib/core/pom.rb +129 -0
- data/lib/core/terminal.rb +28 -8
- data/lib/core/tools.rb +6 -6
- data/lib/core/utils_files.rb +92 -0
- data/lib/core/utils_routes.rb +25 -0
- data/lib/core/utils_strings.rb +45 -0
- data/lib/core/validate.rb +1 -1
- data/lib/routes/build.rb +16 -17
- data/lib/routes/dummy_order.rb +5 -5
- data/lib/routes/fix.rb +49 -0
- data/lib/routes/git_branch.rb +6 -6
- data/lib/routes/git_checkout.rb +42 -33
- data/lib/routes/git_delete.rb +8 -62
- data/lib/routes/git_merge.rb +198 -111
- data/lib/routes/git_pull.rb +11 -11
- data/lib/routes/git_push.rb +21 -12
- data/lib/routes/git_stash.rb +13 -8
- data/lib/routes/git_update.rb +17 -22
- data/lib/routes/jira.rb +3 -3
- data/lib/routes/production_logs.rb +12 -12
- data/lib/routes/reset.rb +1 -1
- data/lib/routes/review.rb +6 -5
- data/lib/routes/scripts_api_docs.rb +5 -5
- data/lib/routes/scripts_branch_cleaner.rb +58 -79
- data/lib/routes/scripts_color.rb +1 -1
- data/lib/routes/scripts_pom_fixer.rb +5 -62
- data/lib/routes/scripts_sonar.rb +82 -0
- data/lib/routes/setup.rb +6 -6
- data/lib/routes/tail.rb +5 -5
- data/lib/routes/test.rb +3 -3
- data/lib/routes/update.rb +1 -1
- metadata +16 -9
- data/lib/routes/scripts_code_sniffer.rb +0 -36
data/lib/routes/git_merge.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class GitMerge < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
|
11
11
|
@source_branches = []
|
12
12
|
@target_branch = nil
|
@@ -19,28 +19,28 @@ module BrightpearlCommand
|
|
19
19
|
def opts_validate
|
20
20
|
|
21
21
|
if @opts[:from_file] && @opts[:open_file]
|
22
|
-
|
22
|
+
App::Terminal::error('Too many flags', "You cannot pass the #{App::Terminal::format_flag('o', false)} and #{App::Terminal::format_flag('f', false)} flags at the same time.", true)
|
23
23
|
end
|
24
24
|
|
25
25
|
unless @args.any?
|
26
|
-
unless @opts[:from_file] || @opts[:open_file]
|
26
|
+
unless @opts[:from_file] || @opts[:open_file] || @opts[:delete_source_branches_local] || @opts[:delete_source_branches_remote]
|
27
27
|
system('bp g m -h')
|
28
28
|
exit
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
if @args[0] ==
|
33
|
-
|
32
|
+
if @args[0] == App::Git::MASTER
|
33
|
+
App::Terminal::error('Not allowed', "You cannot merge #{App::Terminal::format_branch(App::Git::MASTER)}\x1B[38;5;240m to #{App::Terminal::format_branch(App::Git::MASTER)}", true)
|
34
34
|
end
|
35
35
|
|
36
36
|
if @opts[:from_file]
|
37
37
|
unless @args[1].nil?
|
38
|
-
|
38
|
+
App::Terminal::error('Too many parameters', ["When using the #{App::Terminal::format_flag('f')}\x1B[38;5;240m the system only expects one #{App::Terminal::format_action('optional')}\x1B[38;5;240m parameter \xe2\x80\x94 the target branch.", "The amount of parameters you passed were: #{App::Terminal::format_highlight(@args.length)}"], true)
|
39
39
|
end
|
40
|
-
if @opts[:from_file] != '' && File.file?(
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
if @opts[:from_file] != '' && File.file?(App::Enum::GIT_MERGE_DEFAULT_FILE) == false
|
41
|
+
App::Terminal::error("File not found: #{App::Terminal::format_directory(App::Enum::GIT_MERGE_DEFAULT_FILE)}", [
|
42
|
+
"To specify multiple #{App::Terminal::format_branch('source-branches')} try running #{App::Terminal::format_command('bp g m -o')} first."
|
43
|
+
], true)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -48,14 +48,20 @@ module BrightpearlCommand
|
|
48
48
|
|
49
49
|
def opts_routing
|
50
50
|
|
51
|
+
retrieve_source_branches unless @opts[:open_file]
|
52
|
+
retrieve_target_branches unless @opts[:open_file]
|
53
|
+
|
51
54
|
if @opts[:open_file]
|
52
|
-
system("#{
|
55
|
+
system("#{App::Config.param(App::Config::PREFERRED_TEXT_EDITOR)} #{App::Enum::GIT_MERGE_DEFAULT_FILE}")
|
56
|
+
exit
|
57
|
+
elsif @opts[:delete_source_branches_local]
|
58
|
+
delete_source_branches_locally
|
59
|
+
exit
|
60
|
+
elsif @opts[:delete_source_branches_remote]
|
61
|
+
delete_source_branches_remotely
|
53
62
|
exit
|
54
63
|
end
|
55
64
|
|
56
|
-
retrieve_source_branches
|
57
|
-
retrieve_target_branches
|
58
|
-
|
59
65
|
merge
|
60
66
|
|
61
67
|
end
|
@@ -66,37 +72,39 @@ module BrightpearlCommand
|
|
66
72
|
|
67
73
|
# If no 'source branches' are found, select current branch (if both repos on same branch) or throw Error.
|
68
74
|
unless @source_branches.any?
|
69
|
-
code_sb = @git.current_branch_for_repo(
|
70
|
-
db_sb = @git.current_branch_for_repo(
|
75
|
+
code_sb = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
76
|
+
db_sb = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
71
77
|
if code_sb != db_sb
|
72
|
-
|
78
|
+
App::Terminal::error('Cannot reliably determine source branch', ["You're repos are on two different branches:", nil, "Code \xe2\x86\x92 #{App::Terminal::format_branch(code_sb)}", " DB \xe2\x86\x92 #{App::Terminal::format_branch(db_sb)}", nil, 'In this particular scenario, you must explicitly specify a source branch in order to merge.'], true)
|
73
79
|
end
|
74
80
|
@source_branches << code_sb
|
75
81
|
end
|
76
82
|
|
77
|
-
# Check MASTER isn't one of the 'source branches'
|
83
|
+
# Check a RELEASE BRANCH or MASTER isn't one of the 'source branches'
|
78
84
|
@source_branches.each do |branch|
|
79
|
-
if branch ==
|
80
|
-
|
85
|
+
if branch == App::Git::MASTER
|
86
|
+
App::Terminal::error("#{App::Terminal::format_branch(App::Git::MASTER)} has been recognized as a #{App::Terminal::format_highlight('source branch')}", ["If your intention is to merge #{App::Terminal::format_branch(App::Git::MASTER)} into #{App::Terminal::format_branch(@target_branch)}, use #{App::Terminal::format_command('bp g u')} instead."], true)
|
87
|
+
elsif branch =~ App::Git::RELEASE_BRANCH_REGEX
|
88
|
+
App::Terminal::error("#{App::Terminal::format_branch(branch)} has been recognized as a #{App::Terminal::format_highlight('source branch')}", ["You #{App::Terminal::format_invalid('cannot use this script', true)} to merge from a release branch.", "It's usually best to do this manually."], true)
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
84
92
|
# Check a RELEASE-BRANCH isn't one of the 'target branches'
|
85
|
-
if @target_branch =~
|
86
|
-
|
93
|
+
if @target_branch =~ App::Git::RELEASE_BRANCH_REGEX
|
94
|
+
App::Terminal::error("#{App::Terminal::format_branch(@target_branch)} has been recognized as a #{App::Terminal::format_highlight('target branch')}", ["You #{App::Terminal::format_invalid('cannot use this script', true)} to merge to a release branch.", "It's usually best to do this manually."], true)
|
87
95
|
end
|
88
96
|
|
89
97
|
# Initial confirmation
|
90
|
-
unless
|
91
|
-
|
98
|
+
unless App::Terminal::prompt_yes_no("You're about to #{App::Terminal::format_action('initiate a merge')} between the following branch(es):", generate_source_target_text, "Would you like to #{App::Terminal::format_action('CONTINUE')}\x1B[38;5;89m")
|
99
|
+
App::Terminal::abort(nil, nil, true, false)
|
92
100
|
end
|
93
101
|
|
94
102
|
atleast_one_branch_found = false
|
95
103
|
atleast_one_error = false
|
96
|
-
current_branch_cd = @git.current_branch_for_repo(
|
97
|
-
current_branch_db = @git.current_branch_for_repo(
|
98
|
-
cd_repo =
|
99
|
-
db_repo =
|
104
|
+
current_branch_cd = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
105
|
+
current_branch_db = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
106
|
+
cd_repo = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
107
|
+
db_repo = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
100
108
|
non_existent_branches_cd = []
|
101
109
|
non_existent_branches_db = []
|
102
110
|
branches_with_stashes_cd = []
|
@@ -105,32 +113,32 @@ module BrightpearlCommand
|
|
105
113
|
changed_files_db = {}
|
106
114
|
|
107
115
|
# UPDATE MASTER & CHECKOUT BRANCH TO MERGE TO
|
108
|
-
|
116
|
+
App::Terminal::output("Updating #{App::Terminal::format_branch(@target_branch)}")
|
109
117
|
target_branch_data = @git.branch_data(@target_branch, nil, false)
|
110
|
-
if target_branch_data[0][:"#{
|
111
|
-
|
118
|
+
if target_branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false && target_branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
|
119
|
+
App::Terminal::error("Target branch #{App::Terminal::format_branch(@target_branch)} doesn't exist", 'Please check your spelling and try again.', true)
|
112
120
|
end
|
113
121
|
|
114
122
|
# CREATE TARGET BRANCH (CODE OR DB) IF ONE OR THE OTHER DOESN'T EXIST
|
115
|
-
if target_branch_data[0][:"#{
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
elsif target_branch_data[1][:"#{
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
+
if target_branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false
|
124
|
+
App::Terminal::warning("Target #{App::Terminal::format_highlight('CODE')} branch doesn't exist")
|
125
|
+
App::Terminal::output("Creating branch #{App::Terminal::format_branch(@target_branch)} in #{App::Terminal::format_directory(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))}")
|
126
|
+
App::Terminal::error('Not yet implemented', ["The code which should create branch #{App::Terminal::format_branch(@target_branch)} on #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config::WORKSTATION_PATH_TO_BP_CODE))} hasn't been programmed yet.", "Please speak to #{App::Terminal::format_highlight('Albert')}."], true)
|
127
|
+
elsif target_branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
|
128
|
+
App::Terminal::warning("Target #{App::Terminal::format_highlight('DB')} branch doesn't exist")
|
129
|
+
App::Terminal::output("Creating branch #{App::Terminal::format_branch(@target_branch)} in #{App::Terminal::format_directory(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))}")
|
130
|
+
App::Terminal::error('Not yet implemented', ["The code which should create branch #{App::Terminal::format_branch(@target_branch)} on #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config::WORKSTATION_PATH_TO_BP_DB))} hasn't been programmed yet.", "Please speak to #{App::Terminal::format_highlight('Albert')}."], true)
|
123
131
|
end
|
124
132
|
|
125
133
|
commands = [
|
126
|
-
"git checkout #{
|
134
|
+
"git checkout #{App::Git::MASTER}",
|
127
135
|
'git pull',
|
128
136
|
"git checkout #{@target_branch}",
|
129
137
|
'git pull',
|
130
|
-
"git merge #{
|
138
|
+
"git merge #{App::Git::MASTER} --no-edit"
|
131
139
|
]
|
132
140
|
@git.repo_loop.each do |repo_dir|
|
133
|
-
|
141
|
+
App::Terminal::command(commands, repo_dir)
|
134
142
|
end
|
135
143
|
|
136
144
|
# GET DATA FIRST
|
@@ -141,65 +149,65 @@ module BrightpearlCommand
|
|
141
149
|
|
142
150
|
# RUN CHECKS (AND CHECKOUT BRANCHES WHICH DON'T EXIST LOCALLY)
|
143
151
|
branches_data.each do |branch_data|
|
144
|
-
if branch_data[0][:"#{
|
152
|
+
if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] || branch_data[1][:"#{App::Git::BRANCH_EXISTS}"]
|
145
153
|
atleast_one_branch_found = true
|
146
154
|
end
|
147
|
-
if branch_data[0][:"#{
|
148
|
-
non_existent_branches_cd << branch_data[0][:"#{
|
155
|
+
if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false
|
156
|
+
non_existent_branches_cd << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
|
149
157
|
end
|
150
|
-
if branch_data[1][:"#{
|
151
|
-
non_existent_branches_db << branch_data[0][:"#{
|
158
|
+
if branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
|
159
|
+
non_existent_branches_db << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
|
152
160
|
end
|
153
|
-
if branch_data[0][:"#{
|
154
|
-
branches_with_stashes_cd << branch_data[0][:"#{
|
161
|
+
if branch_data[0][:"#{App::Git::BRANCH_HAS_STASH}"]
|
162
|
+
branches_with_stashes_cd << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
|
155
163
|
end
|
156
|
-
if branch_data[1][:"#{
|
157
|
-
branches_with_stashes_db << branch_data[1][:"#{
|
164
|
+
if branch_data[1][:"#{App::Git::BRANCH_HAS_STASH}"]
|
165
|
+
branches_with_stashes_db << branch_data[1][:"#{App::Git::BRANCH_NAME}"]
|
158
166
|
end
|
159
|
-
if branch_data[0][:"#{
|
167
|
+
if branch_data[0][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"] == false && branch_data[0][:"#{App::Git::BRANCH_EXISTS}"]
|
160
168
|
commands_cd = [
|
161
|
-
"git checkout #{branch_data[0][:"#{
|
169
|
+
"git checkout #{branch_data[0][:"#{App::Git::BRANCH_NAME}"]}",
|
162
170
|
'git pull',
|
163
171
|
"git checkout #{current_branch_cd}"
|
164
172
|
]
|
165
|
-
|
173
|
+
App::Terminal::command(commands_cd, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
166
174
|
end
|
167
|
-
if branch_data[1][:"#{
|
175
|
+
if branch_data[1][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"] == false && branch_data[1][:"#{App::Git::BRANCH_EXISTS}"]
|
168
176
|
commands_db = [
|
169
|
-
"git checkout #{branch_data[1][:"#{
|
177
|
+
"git checkout #{branch_data[1][:"#{App::Git::BRANCH_NAME}"]}",
|
170
178
|
'git pull',
|
171
179
|
"git checkout #{current_branch_db}"
|
172
180
|
]
|
173
|
-
|
181
|
+
App::Terminal::command(commands_db, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
177
185
|
puts # DO NOT REMOVE.
|
178
186
|
|
179
187
|
if non_existent_branches_cd.any? || branches_with_stashes_cd.any?
|
180
|
-
puts "\n #{
|
188
|
+
puts "\n #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))}\n\n"
|
181
189
|
end
|
182
190
|
if non_existent_branches_cd.any?
|
183
|
-
|
191
|
+
App::Terminal::warning("The following branches #{App::Terminal::format_invalid('could not be found', true)} \xe2\x80\x94 #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))}", non_existent_branches_cd, false)
|
184
192
|
atleast_one_error = true
|
185
193
|
end
|
186
194
|
if branches_with_stashes_cd.any?
|
187
|
-
|
195
|
+
App::Terminal::warning("The following branches #{App::Terminal::format_invalid('have stashes', true)} \xe2\x80\x94 #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))}", branches_with_stashes_cd, false)
|
188
196
|
atleast_one_error = true
|
189
197
|
end
|
190
198
|
if non_existent_branches_db.any? || branches_with_stashes_db.any?
|
191
|
-
puts "\n #{
|
199
|
+
puts "\n #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))}\n\n"
|
192
200
|
end
|
193
201
|
if non_existent_branches_db.any?
|
194
|
-
|
202
|
+
App::Terminal::warning("The following branches #{App::Terminal::format_invalid('could not be found', true)} \xe2\x80\x94 #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))}", non_existent_branches_db, false)
|
195
203
|
atleast_one_error = true
|
196
204
|
end
|
197
205
|
if branches_with_stashes_db.any?
|
198
|
-
|
206
|
+
App::Terminal::warning("The following branches #{App::Terminal::format_invalid('have stashes', true)} \xe2\x80\x94 #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))}", branches_with_stashes_db, false)
|
199
207
|
atleast_one_error = true
|
200
208
|
end
|
201
209
|
if atleast_one_branch_found == false
|
202
|
-
|
210
|
+
App::Terminal::error('Source branches not found', 'Nothing to merge. Aborting script.', true)
|
203
211
|
end
|
204
212
|
|
205
213
|
non_existent_branches_cd_dup = non_existent_branches_cd.dup
|
@@ -212,93 +220,131 @@ module BrightpearlCommand
|
|
212
220
|
end
|
213
221
|
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.")
|
214
222
|
|
215
|
-
unless
|
216
|
-
|
223
|
+
unless App::Terminal::prompt_yes_no("You're about to #{App::Terminal::format_action('merge')} between following branch(es):", source_target_text, "Are you absolutely sure you would like to #{App::Terminal::format_action('CONTINUE')}\x1B[38;5;89m with the merge?")
|
224
|
+
App::Terminal::abort(nil, nil, true, false)
|
217
225
|
end
|
218
226
|
|
219
227
|
# MERGE STARTS HERE !!
|
220
228
|
branches_data.each do |branch_data|
|
221
229
|
|
222
|
-
branch_name = branch_data[0][:"#{
|
230
|
+
branch_name = branch_data[0][:"#{App::Git::BRANCH_NAME}"]
|
223
231
|
commands_1 = [
|
224
|
-
"git checkout #{branch_name}"
|
232
|
+
"git checkout #{branch_name}",
|
233
|
+
'git pull'
|
225
234
|
]
|
226
235
|
commands_2 = [
|
227
|
-
"git merge #{
|
236
|
+
"git merge #{App::Git::MASTER} --no-edit"
|
228
237
|
]
|
229
238
|
commands_3 = [
|
230
|
-
"git diff --name-only #{
|
239
|
+
"git diff --name-only #{App::Git::MASTER}"
|
231
240
|
]
|
232
241
|
commands_4 = [
|
233
242
|
'git push',
|
234
243
|
"git checkout #{@target_branch}"
|
235
244
|
]
|
236
245
|
commands_5 = [
|
237
|
-
"git merge #{branch_name}",
|
246
|
+
"git merge #{branch_name} --no-edit",
|
238
247
|
]
|
239
248
|
commands_6 = []
|
240
|
-
if @target_branch !=
|
249
|
+
if @target_branch != App::Git::MASTER
|
241
250
|
commands_6 << 'git push'
|
242
251
|
end
|
243
252
|
|
253
|
+
mc_information_msg = "Please #{App::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing."
|
254
|
+
mc_confirmation_msg = "Have you #{App::Terminal::format_highlight('resolved your conflicts')}\x1B[38;5;89m and #{App::Terminal::format_action('committed')}\x1B[38;5;89m the changes?"
|
255
|
+
|
244
256
|
# CODE BRANCHES
|
245
257
|
unless non_existent_branches_cd.include?(branch_name)
|
246
|
-
|
247
|
-
|
248
|
-
|
258
|
+
App::Terminal::command(commands_1, cd_repo)
|
259
|
+
|
260
|
+
# FIND OUT IF WE NEED TO FIX POM FILES
|
261
|
+
pom_files_to_fix = App::Pom::get_files_to_change
|
262
|
+
if pom_files_to_fix.any?
|
263
|
+
App::Pom::unsnapshot_files(pom_files_to_fix, @target_branch, false)
|
264
|
+
end
|
265
|
+
|
266
|
+
merge_master_result = App::Terminal::command(commands_2, cd_repo)
|
249
267
|
if merge_master_result[0] == false
|
250
|
-
|
268
|
+
unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(App::Git::MASTER)} \xe2\x86\x92 #{App::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))})", mc_information_msg], mc_confirmation_msg)
|
269
|
+
App::Terminal::abort(nil, nil, true, false)
|
270
|
+
end
|
251
271
|
end
|
252
|
-
|
253
|
-
|
254
|
-
|
272
|
+
|
273
|
+
changed_files_code["#{branch_name}"] = App::Terminal::command_capture(commands_3, cd_repo)
|
274
|
+
App::Terminal::command(commands_4, cd_repo)
|
275
|
+
merge_to_target = App::Terminal::command(commands_5, cd_repo)
|
255
276
|
if merge_to_target[0] == false
|
256
|
-
|
277
|
+
unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{App::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))})", mc_information_msg], mc_confirmation_msg)
|
278
|
+
App::Terminal::abort(nil, nil, true, false)
|
279
|
+
end
|
257
280
|
end
|
258
281
|
if commands_6.any?
|
259
|
-
|
282
|
+
App::Terminal::command(commands_6, cd_repo)
|
260
283
|
end
|
261
284
|
end
|
262
285
|
|
263
286
|
# DB BRANCHES
|
264
287
|
unless non_existent_branches_db.include?(branch_name)
|
265
|
-
|
266
|
-
|
267
|
-
merge_master_result = Brightpearl::Terminal::command(commands_2, db_repo)
|
288
|
+
App::Terminal::command(commands_1, db_repo)
|
289
|
+
merge_master_result = App::Terminal::command(commands_2, db_repo)
|
268
290
|
if merge_master_result[0] == false
|
269
|
-
|
291
|
+
unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(App::Git::MASTER)} \xe2\x86\x92 #{App::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))})", mc_information_msg], mc_confirmation_msg)
|
292
|
+
App::Terminal::abort(nil, nil, true, false)
|
293
|
+
end
|
270
294
|
end
|
271
|
-
changed_files_db["#{branch_name}"] =
|
272
|
-
|
273
|
-
merge_to_target =
|
295
|
+
changed_files_db["#{branch_name}"] = App::Terminal::command_capture(commands_3, db_repo)
|
296
|
+
App::Terminal::command(commands_4, db_repo, false)
|
297
|
+
merge_to_target = App::Terminal::command(commands_5, db_repo)
|
274
298
|
if merge_to_target[0] == false
|
275
|
-
|
299
|
+
unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(branch_name)} \xe2\x86\x92 #{App::Terminal::format_branch(@target_branch)} \xe2\x80\x94 (#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))})", mc_information_msg], mc_confirmation_msg)
|
300
|
+
App::Terminal::abort(nil, nil, true, false)
|
301
|
+
end
|
276
302
|
end
|
277
303
|
if commands_6.any?
|
278
|
-
|
304
|
+
App::Terminal::command(commands_6, db_repo)
|
279
305
|
end
|
280
306
|
end
|
281
307
|
|
282
308
|
end
|
283
309
|
|
284
|
-
|
310
|
+
App::Terminal::success('It seems as if everything ran smoothly', "#{@source_branches.count} #{(@source_branches.count) == 1 ? 'branch has' : 'branches have'} been successfully merged to #{App::Terminal::format_branch(@target_branch)}")
|
285
311
|
|
286
|
-
|
312
|
+
# SANITY CHECK SCRIPT
|
313
|
+
@source_branches.each do |x|
|
314
|
+
grep_string = x.split('-')
|
315
|
+
grep_string = "BP-#{grep_string[grep_string.count - 1]}"
|
316
|
+
puts "\x1B[38;5;39m#{x}\x1B[0m \xe2\x80\x94 (#{grep_string})"
|
317
|
+
system("cd #{App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)} && git log | grep '#{grep_string}' --color=auto")
|
318
|
+
system("cd #{App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)} && git log | grep '#{grep_string}' --color=auto")
|
319
|
+
end
|
320
|
+
puts
|
287
321
|
|
288
|
-
|
322
|
+
@git.check_for_stash(true)
|
289
323
|
|
290
|
-
|
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
|
324
|
+
end
|
299
325
|
|
300
|
-
|
326
|
+
def delete_source_branches_locally
|
327
|
+
|
328
|
+
# Initial confirmation
|
329
|
+
unless App::Terminal::prompt_yes_no("You're about to #{App::Terminal::format_action('delete')} the following branch(es) #{App::Terminal::format_highlight('locally')}:", generate_source_target_text, "Would you like to #{App::Terminal::format_action('CONTINUE')}\x1B[38;5;89m")
|
330
|
+
App::Terminal::abort(nil, nil, true, false)
|
331
|
+
end
|
301
332
|
|
333
|
+
@source_branches.each do |branch_name|
|
334
|
+
App::GitDelete::delete_local(branch_name, false, @git)
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
def delete_source_branches_remotely
|
340
|
+
|
341
|
+
# Initial confirmation
|
342
|
+
unless App::Terminal::prompt_yes_no("You're about to #{App::Terminal::format_action('delete')} the following branch(es) #{App::Terminal::format_highlight('remotely')}:", generate_source_target_text, "Would you like to #{App::Terminal::format_action('CONTINUE')}\x1B[38;5;89m")
|
343
|
+
App::Terminal::abort(nil, nil, true, false)
|
344
|
+
end
|
345
|
+
|
346
|
+
@source_branches.each do |branch_name|
|
347
|
+
App::GitDelete::delete_remote(branch_name, false, @git)
|
302
348
|
end
|
303
349
|
|
304
350
|
end
|
@@ -306,8 +352,8 @@ module BrightpearlCommand
|
|
306
352
|
private
|
307
353
|
|
308
354
|
def retrieve_source_branches
|
309
|
-
if @opts[:from_file]
|
310
|
-
File.open(
|
355
|
+
if @opts[:from_file] || @opts[:delete_source_branches_local] || @opts[:delete_source_branches_remote]
|
356
|
+
File.open(App::Enum::GIT_MERGE_DEFAULT_FILE).each do |line|
|
311
357
|
line_trimmed = line.gsub(/\s+/, '')
|
312
358
|
if line_trimmed != ''
|
313
359
|
line_split = line_trimmed.split(',')
|
@@ -318,27 +364,68 @@ module BrightpearlCommand
|
|
318
364
|
source_branches = @args[0].split(',')
|
319
365
|
@source_branches.concat(source_branches)
|
320
366
|
end
|
321
|
-
|
367
|
+
|
368
|
+
# Un-comment to sort alphanumerically.
|
369
|
+
# @source_branches.sort_by! { |m| m.downcase }
|
370
|
+
|
322
371
|
@source_branches.uniq!
|
372
|
+
|
373
|
+
# If branch(es) was/were specified as '1234' or '12345', this code tries to resolve it automatically as bp-12345/bug-12345/feature-12345
|
374
|
+
branches_to_resolve = {}
|
375
|
+
@source_branches.each do |branch_name|
|
376
|
+
if branch_name =~ /\A\d{4,5}\z/
|
377
|
+
branches_to_resolve[branch_name] = false
|
378
|
+
end
|
379
|
+
end
|
380
|
+
if branches_to_resolve.any?
|
381
|
+
new_source_branches = []
|
382
|
+
@source_branches.each do |branch_name|
|
383
|
+
unless branches_to_resolve.keys.include?(branch_name)
|
384
|
+
new_source_branches << branch_name unless branch_name == '' || branch_name.nil?
|
385
|
+
end
|
386
|
+
end
|
387
|
+
@git.get_all_branches_as_array.each do |possible_branch|
|
388
|
+
branches_to_resolve.keys.each do |branch_to_resolve|
|
389
|
+
if possible_branch =~ /(bug|bp|feature)-#{branch_to_resolve}\z/i
|
390
|
+
|
391
|
+
# If more than one possible branch exists, IE: bug-14145 & bp-14145
|
392
|
+
unless branches_to_resolve[branch_to_resolve] == false
|
393
|
+
App::Terminal::error("More than one possible branch found for string: #{App::Terminal::format_highlight(branch_to_resolve)}", [App::Terminal::format_branch(possible_branch), App::Terminal::format_branch(branches_to_resolve[branch_to_resolve]), nil, "In this case, you must specify the branch name #{App::Terminal::format_highlight('explicitly')}."], true)
|
394
|
+
end
|
395
|
+
|
396
|
+
branches_to_resolve[branch_to_resolve] = possible_branch
|
397
|
+
App::Terminal::output("Resolved branch #{App::Terminal::format_branch(possible_branch)} from string: #{App::Terminal::format_highlight(branch_to_resolve)}", App::Terminal::MSG_AUTOMATIC)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
branches_to_resolve.each do |branch_to_resolve|
|
402
|
+
if branch_to_resolve[1] == false
|
403
|
+
App::Terminal::error("No branch found for string: #{App::Terminal::format_highlight(branch_to_resolve[0])}", ['Please check your input and try again.'], true)
|
404
|
+
end
|
405
|
+
new_source_branches << branch_to_resolve[1] unless branch_to_resolve[1] == '' || branch_to_resolve[1].nil?
|
406
|
+
end
|
407
|
+
@source_branches = new_source_branches
|
408
|
+
end
|
409
|
+
|
323
410
|
unless @source_branches.any?
|
324
411
|
error_text = nil
|
325
412
|
if @opts[:from_file]
|
326
|
-
error_text = "No source branches found in: #{
|
413
|
+
error_text = "No source branches found in: #{App::Terminal::format_directory(App::Enum::GIT_MERGE_DEFAULT_FILE)}"
|
327
414
|
end
|
328
|
-
|
415
|
+
App::Terminal::error('Cannot determine source branch(es)', error_text, true)
|
329
416
|
end
|
330
417
|
end
|
331
418
|
|
332
419
|
def retrieve_target_branches
|
333
420
|
if @opts[:from_file]
|
334
421
|
if @args[0].nil?
|
335
|
-
@target_branch = @git.current_branch_for_repo(
|
422
|
+
@target_branch = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
336
423
|
else
|
337
424
|
@target_branch = @args[0]
|
338
425
|
end
|
339
426
|
else
|
340
427
|
if @args[1].nil?
|
341
|
-
@target_branch = @git.current_branch_for_repo(
|
428
|
+
@target_branch = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
342
429
|
else
|
343
430
|
@target_branch = @args[1]
|
344
431
|
end
|
data/lib/routes/git_pull.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class GitPull < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
|
11
11
|
opts_validate
|
12
12
|
opts_routing
|
@@ -16,7 +16,7 @@ module BrightpearlCommand
|
|
16
16
|
def opts_validate
|
17
17
|
|
18
18
|
if @args[0].nil?
|
19
|
-
@args[0] = @git.current_branch_for_repo(
|
19
|
+
@args[0] = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -29,17 +29,17 @@ module BrightpearlCommand
|
|
29
29
|
|
30
30
|
def git_pull
|
31
31
|
|
32
|
-
@git.check_for_same_branch(
|
33
|
-
branch_code = @git.current_branch_for_repo(
|
34
|
-
branch_db = @git.current_branch_for_repo(
|
35
|
-
if
|
36
|
-
"#{
|
37
|
-
"#{
|
32
|
+
@git.check_for_same_branch(App::Git::SAME_BRANCH_WARNING)
|
33
|
+
branch_code = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
34
|
+
branch_db = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
35
|
+
if App::Terminal::prompt_yes_no("#{App::Terminal::format_action('pull')} the following repos:", [
|
36
|
+
"#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} will pull #{App::Terminal::format_branch(branch_code)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_code}")}",
|
37
|
+
"#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} will pull #{App::Terminal::format_branch(branch_db)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_db}")}"
|
38
38
|
])
|
39
39
|
@git.check_for_uncommitted_files(true)
|
40
40
|
@git.repo_loop.each do |repo_dir|
|
41
|
-
unless
|
42
|
-
|
41
|
+
unless App::Terminal::command_capture("git pull origin #{@git.current_branch_for_repo(repo_dir)}", repo_dir)
|
42
|
+
App::Terminal::warning('Something went wrong', "Not sure what the reason was, but doing a #{App::Terminal::format_command('git pull')} on #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} was unsuccessful.")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
@git.check_for_stash(true)
|