Class: AppCommand::GitMerge

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/git_merge.rb

Instance Method Summary collapse

Instance Method Details

#build_services(preceding_blank_line = true) ⇒ Object


418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/routes/git_merge.rb', line 418

def build_services(preceding_blank_line = true)
    services_to_build = []
    directories_to_build = []
    changed_files = App::Terminal::command_capture("git diff origin/#{App::Git::MASTER} --name-only", App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE), false, false)
    if changed_files[0] != ''
        puts
        changed_files[0].split("\n").each do |file|
            if file.strip =~ /\Aservices\//i
                service_name = file.strip.split('/')
                services_to_build << service_name[2]
                directories_to_build << "#{service_name[0]}/#{service_name[1]}/#{service_name[2]}"
                puts "   \x1B[38;5;223m#{file}\x1B[0m"
            else
                puts "   \x1B[38;5;240m#{file}\x1B[0m"
            end
        end
    end
    services_to_build.uniq!
    directories_to_build.uniq!
    build_text = []
    services_to_build.each do |service|
        build_text << service
    end
    command_line_command = ''
    directories_to_build.each_with_index do |directory, index|
        if [
            'services/dev-support/fitnesse-support'
        ].include?(directory)
            command_line_command = "#{command_line_command}cd #{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE)}/#{directory} && mvn clean install | grep -i \"success\\|failure\""
        else
            command_line_command = "#{command_line_command}cd #{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE)}/#{directory} && mvn clean install deploy | grep -i \"success\\|failure\""
        end

        if index != directories_to_build.size - 1
            command_line_command = "#{command_line_command} && \n"
        end
    end
    if services_to_build.any?
        App::Terminal::info("Please build the following #{App::Terminal::format_highlight('Services')} before committing to #{App::Terminal::format_branch(App::Git::MASTER)}:", build_text, preceding_blank_line)
        puts
        puts command_line_command
        puts
    else
        if changed_files[0] != ''
            App::Terminal::info("No #{App::Terminal::format_highlight('Services')} need building. The #{App::Terminal::format_highlight('only', true)} files changed between #{App::Terminal::format_branch(@target_branch)} and origin/#{App::Terminal::format_branch(App::Git::MASTER)} are:", changed_files[0], preceding_blank_line)
        else
            App::Terminal::info("No #{App::Terminal::format_highlight('Services')} need building.", nil, preceding_blank_line)
        end
    end
end

#delete_source_branches_locallyObject


362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/routes/git_merge.rb', line 362

def delete_source_branches_locally

    # Initial confirmation
    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")
        App::Terminal::abort
    end

    @source_branches.each do |branch_name|
        App::GitDelete::delete_local(branch_name, false, @git)
    end

end

#delete_source_branches_remotelyObject


375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/routes/git_merge.rb', line 375

def delete_source_branches_remotely

    # Initial confirmation
    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")
        App::Terminal::abort
    end

    @source_branches.each do |branch_name|
        App::GitDelete::delete_remote(branch_name, false, @git)
    end

end

#executeObject


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/routes/git_merge.rb', line 5

def execute

    @opts = command_options
    @args = arguments
    @git = App::Git.new

    @source_branches = []
    @target_branch = nil

    opts_validate
    opts_routing

end

#mergeObject


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/routes/git_merge.rb', line 73

def merge

    @git.check_for_uncommitted_files(false, 'Aborting the merge!')

    # If no 'source branches' are found, select current branch (if both repos on same branch) or throw Error.
    unless @source_branches.any?
        code_sb = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
        db_sb = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
        if code_sb != db_sb
            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)
        end
        @source_branches << code_sb
    end

    # Check a RELEASE BRANCH or MASTER isn't one of the 'source branches'
    @source_branches.each do |branch|
        if branch == App::Git::MASTER
            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)
        elsif branch =~ App::Git::RELEASE_BRANCH_REGEX
            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)
        end
    end

    # Check a RELEASE-BRANCH isn't one of the 'target branches'
    if @target_branch =~ App::Git::RELEASE_BRANCH_REGEX
        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)
    end

    # Initial confirmation
    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")
        App::Terminal::abort
    end

    atleast_one_branch_found = false
    atleast_one_error = false
    current_branch_cd = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
    current_branch_db = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
    cd_repo = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
    db_repo = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
    non_existent_branches_cd = []
    non_existent_branches_db = []
    branches_with_stashes_cd = []
    branches_with_stashes_db = []
    changed_files_code = {}
    changed_files_db = {}
    ran_db_update = false

    target_branch_data = @git.branch_data(@target_branch, nil, false)

    # IF TARGET BRANCH DOESN'T EXIST...
    if target_branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false && target_branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
        App::Terminal::error("Target branch #{App::Terminal::format_branch(@target_branch)} doesn't exist", 'Please check your spelling and try again.', true)
    end

    # CREATE TARGET BRANCH (CODE OR DB) IF ONE OR THE OTHER DOESN'T EXIST (THIS CODE IS CURRENTLY NEVER REACHED)
    if target_branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false
        App::Terminal::warning("Target #{App::Terminal::format_highlight('CODE')} branch doesn't exist")
        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))}")
        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)
    elsif target_branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
        App::Terminal::warning("Target #{App::Terminal::format_highlight('DB')} branch doesn't exist")
        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))}")
        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)
    end

    # UPDATE MASTER & CHECKOUT BRANCH TO MERGE TO
    App::Terminal::output("Updating #{App::Terminal::format_branch(@target_branch)}")

    commands = [
        "git checkout #{App::Git::MASTER}",
        'git pull'
    ]
    if @target_branch != App::Git::MASTER
        additional_commands = [
            "git checkout #{@target_branch}",
            'git pull',
            "git merge #{App::Git::MASTER} --no-edit"
        ]
        commands.push(*additional_commands)
    end

    @git.repo_loop.each do |repo_dir|
        App::Terminal::command(commands, repo_dir)
    end

    # GET DATA FIRST
    branches_data = []
    @source_branches.each do |branch_name|
        branches_data << @git.branch_data(branch_name, nil, false)
    end

    # RUN CHECKS (AND CHECKOUT BRANCHES WHICH DON'T EXIST LOCALLY)
    branches_data.each_with_index do |branch_data, idx|
        if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] || branch_data[1][:"#{App::Git::BRANCH_EXISTS}"]
            atleast_one_branch_found = true
        end
        if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false
            non_existent_branches_cd << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
        end
        if branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
            non_existent_branches_db << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
        end
        if branch_data[0][:"#{App::Git::BRANCH_HAS_STASH}"]
            branches_with_stashes_cd << branch_data[0][:"#{App::Git::BRANCH_NAME}"]
        end
        if branch_data[1][:"#{App::Git::BRANCH_HAS_STASH}"]
            branches_with_stashes_db << branch_data[1][:"#{App::Git::BRANCH_NAME}"]
        end
        if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"]
            commands_cd = [
                "git checkout #{branch_data[0][:"#{App::Git::BRANCH_NAME}"]}",
                'git pull'
            ]
            commands_cd << "git checkout #{current_branch_cd}" if idx == (branches_data.length - 1)
            App::Terminal::command(commands_cd, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
        end
        if branch_data[1][:"#{App::Git::BRANCH_EXISTS}"]
            commands_db = [
                "git checkout #{branch_data[1][:"#{App::Git::BRANCH_NAME}"]}",
                'git pull'
            ]
            commands_db << "git checkout #{current_branch_db}" if idx == (branches_data.length - 1)
            App::Terminal::command(commands_db, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
        end
    end

    puts # DO NOT REMOVE.

    if non_existent_branches_cd.any?
        App::Terminal::warning("The following branches could not be found \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)
        atleast_one_error = true
    end
    if branches_with_stashes_cd.any?
        App::Terminal::warning("The following branches have #{App::Terminal::format_highlight('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)
        atleast_one_error = true
    end
    if non_existent_branches_db.any?
        App::Terminal::warning("The following branches could not be found \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)
        atleast_one_error = true
    end
    if branches_with_stashes_db.any?
        App::Terminal::warning("The following branches have #{App::Terminal::format_highlight('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)
        atleast_one_error = true
    end
    if atleast_one_branch_found == false
        App::Terminal::error('Source branches not found', 'Nothing to merge. Aborting script.', true)
    end

    non_existent_branches_cd_dup = non_existent_branches_cd.dup
    non_existent_branches_db_dup = non_existent_branches_db.dup

    source_target_text = generate_source_target_text(non_existent_branches_cd_dup.concat(non_existent_branches_db_dup).uniq!)
    source_target_text.unshift('')
    if atleast_one_error
        source_target_text.unshift('Although issues were detected, the script determined that these are non-fatal and can continue with the merge.')
    end
    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.")

    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?")
        App::Terminal::abort
    end

    # MERGE STARTS HERE !!
    branches_data.each do |branch_data|

        branch_name = branch_data[0][:"#{App::Git::BRANCH_NAME}"]

        commands_1 = [
            "git checkout #{branch_name}",
            'git pull'
        ]
        commands_2 = [
            "git merge #{App::Git::MASTER} --no-edit"
        ]
        commands_3 = [
            "git diff --name-only #{App::Git::MASTER}"
        ]
        commands_4 = @opts[:push_changes] ? ['git push'] : []
        commands_4 << "git checkout #{@target_branch}"
        commands_5 = [
            "git merge #{branch_name} --no-edit",
        ]
        commands_6 = []
        if @target_branch != App::Git::MASTER
            commands_6 << 'git push'
        end

        mc_information_msg = "Please #{App::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing."
        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?"

        # CODE BRANCHES
        unless non_existent_branches_cd.include?(branch_name)

            App::Terminal::info("Merging: #{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)))}")
            App::Terminal::command(commands_1, cd_repo)

            # FIND OUT IF WE NEED TO FIX POM FILES
            pom_files_to_fix = App::Pom::get_files_to_change
            if pom_files_to_fix.any?
                App::Pom::unsnapshot_files(pom_files_to_fix, @target_branch, false, App::Enum::YES, App::Enum::YES, App::Enum::NO)
            end

            merge_master_result = App::Terminal::command(commands_2, cd_repo)
            if merge_master_result[0] == false
                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)
                    App::Terminal::abort
                end
            end

            changed_files_code["#{branch_name}"] = App::Terminal::command_capture(commands_3, cd_repo)

            App::Terminal::command(commands_4, cd_repo)

            merge_to_target = App::Terminal::command(commands_5, cd_repo)
            if merge_to_target[0] == false
                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)
                    App::Terminal::abort
                end
            end
            if commands_6.any?
                App::Terminal::command(commands_6, cd_repo)
            end
        end

        # DB BRANCHES
        unless non_existent_branches_db.include?(branch_name)

            App::Terminal::info("Merging: #{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)))}")
            App::Terminal::command(commands_1, db_repo)
            merge_master_result = App::Terminal::command(commands_2, db_repo)
            if merge_master_result[0] == false
                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)
                    App::Terminal::abort
                end
            end
            changed_files_db["#{branch_name}"] = App::Terminal::command_capture(commands_3, db_repo)

            App::Terminal::command(commands_4, db_repo, false)
            merge_to_target = App::Terminal::command(commands_5, db_repo)
            if merge_to_target[0] == false
                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)
                    App::Terminal::abort
                end
            end

            # SQL UPDATE
            unless changed_files_db["#{branch_name}"].nil? || changed_files_db["#{branch_name}"] == '' || changed_files_db["#{branch_name}"] == ['']
                App::Terminal::warning("Detected SQL Update. Following files were changed in #{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)))}", changed_files_db["#{branch_name}"])
                begin
                    App::SqlUpdate::run_sql_update(branch_name)
                end
                ran_db_update = true
            end

            if commands_6.any?
                App::Terminal::command(commands_6, db_repo)
            end
        end

    end

    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)}")

    if ran_db_update
        App::Terminal::info("You have run a #{App::Terminal::format_highlight('DB Update')}. Don't forget to run the following on your VM:", %W(#{App::Terminal::format_command('update-skeleton')} #{App::Terminal::format_command('update-fitnesse')}), false)
    end

    build_services(false)
    sanity_check(false)

    reminders = [
        'Run the PHP Unit tests?',
        'Run the PHP Behat tests?',
        'Built and deployed all service?',
        "Run the sonar checker? \xe2\x80\x94 #{App::Terminal::format_command('bp s s')}",
        'Re-gulped everything?',
        'Updated FitNesse DB?',
        'Updated Skeleton DBs?',
        'Removed all sandpit files?',
    ]

    puts
    App::Terminal::info("#{App::Terminal::format_action('Final Reminders')} \xe2\x80\x94 Have you:", reminders, false)
    puts

    @git.check_for_stash(true)

end

#opts_routingObject


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/routes/git_merge.rb', line 47

def opts_routing

    retrieve_source_branches unless @opts[:open_file]
    retrieve_target_branches unless @opts[:open_file]

    if @opts[:sanity_check]
        sanity_check
        exit
    elsif @opts[:build_services]
        build_services
        exit
    elsif @opts[:open_file]
        system("#{App::Config.param(App::Config::PREFERRED_TEXT_EDITOR)} #{App::Git::GIT_MERGE_DEFAULT_FILE}")
        exit
    elsif @opts[:delete_source_branches_local]
        delete_source_branches_locally
        exit
    elsif @opts[:delete_source_branches_remote]
        delete_source_branches_remotely
        exit
    end

    merge

end

#opts_validateObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/routes/git_merge.rb', line 19

def opts_validate

    if @opts[:from_file] && @opts[:open_file]
        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)
    end

    unless @args.any?
        unless @opts[:from_file] || @opts[:open_file] || @opts[:delete_source_branches_local] || @opts[:delete_source_branches_remote] || @opts[:sanity_check] || @opts[:build_services]
            system('bp g m -h')
            exit
        end
    end

    if @args[0] == App::Git::MASTER && !@opts[:from_file]
        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)
    end

    if @opts[:from_file]
        unless @args[1].nil?
            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)
        end
        if @opts[:from_file] != '' && File.file?(File.expand_path(App::Git::GIT_MERGE_DEFAULT_FILE)) == false
            App::Terminal::error("File not found: #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)}", ["To specify multiple #{App::Terminal::format_branch('source-branches')} try running #{App::Terminal::format_command('bp g m -o')} first.", "A likely cause for this message is that #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)} doesn't exist."], true)
        end
    end

end

#sanity_check(preceding_blank_line = true) ⇒ Object


388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/routes/git_merge.rb', line 388

def sanity_check(preceding_blank_line = true)
    if @source_branches.any?
        jira_numbers_resolved = false
        @source_branches.each do |source_branch|
            if source_branch =~ /\d{4,5}/i
                jira_numbers_resolved = true
            end
        end
        unless jira_numbers_resolved
            App::Terminal::info("No #{App::Terminal::format_highlight('Sanity Check')} could be run because the system couldn't resolve any jira numbers from:", @source_branches, preceding_blank_line)
            return
        end
        App::Terminal::info("Running #{App::Terminal::format_highlight('Sanity Check')} against: #{App::Terminal::format_branch(@target_branch)}", nil, preceding_blank_line)
        @source_branches.each do |source_branch|
            jira_numbers = source_branch.scan(/\d{4,5}/i)
            if jira_numbers.any?
                jira_numbers.each do |jira_number|
                    unless jira_number == ''
                        sanity_check_grep(jira_number, source_branch, @target_branch)
                    end

                end
            end
        end
    else
        App::Terminal::error("Cannot run  #{App::Terminal::format_highlight('Sanity Check')}", 'No source branches specified.', true, preceding_blank_line)
    end
    puts
end