@@ -224,7 +224,7 @@ namespace :git do
224
224
desc 'git push on all the repos'
225
225
task :push , :force do |t , args |
226
226
branch = `git rev-parse --abbrev-ref HEAD`
227
- if args [ :force ]
227
+ if should_force? ( args )
228
228
run_command "git push origin #{ branch } --force-with-lease"
229
229
else
230
230
run_command "git push origin #{ branch } "
@@ -396,8 +396,8 @@ namespace :ci do
396
396
397
397
desc "Updates the CI files and creates a PR"
398
398
task :create_pr_with_updates , :custom_pr_comment , :force do |t , args |
399
- opts = { except : %w[ rspec-rails ] }
400
- force_update ( update_ci_files_in_repos ( opts ) , args [ :custom_pr_comment ] , args [ :force ] == "force" , opts )
399
+ opts = { except : %w[ rspec-rails ] , force : should_force? ( args ) }
400
+ force_update ( update_ci_files_in_repos ( opts ) , args [ :custom_pr_comment ] , opts [ :force ] , opts )
401
401
end
402
402
end
403
403
@@ -488,7 +488,7 @@ namespace :common_plaintext_files do
488
488
489
489
desc "Updates the common plaintext files files and creates a PR"
490
490
task :create_pr_with_updates , :custom_pr_comment , :force do |_t , args |
491
- force_update ( update_common_plaintext_files_in_repos , args [ :custom_pr_comment ] , args [ :force ] == "force" )
491
+ force_update ( update_common_plaintext_files_in_repos , args [ :custom_pr_comment ] , should_force? ( args ) )
492
492
end
493
493
end
494
494
@@ -555,9 +555,14 @@ def assert_clean_git_status(name)
555
555
end
556
556
end
557
557
558
- def confirm_branch_name ( name )
558
+ def confirm_branch_name ( name , opts = { } )
559
559
return name unless system ( "git show-branch #{ name } > /dev/null 2>&1" )
560
560
561
+ if opts [ :force ]
562
+ `git branch -D #{ name } `
563
+ return name
564
+ end
565
+
561
566
puts "Branch #{ name } already exists, delete? [Y/n] or rename new branch? [r[ename] <name>]"
562
567
case input = STDIN . gets . downcase
563
568
when /^y/i
@@ -598,6 +603,14 @@ def force_update(branch, custom_pr_comment, skip_confirmation=false, opts={})
598
603
end
599
604
end
600
605
606
+ def should_force? ( opts = { } )
607
+ force = opts [ :force ]
608
+ %w[ force t true ] . each do |text |
609
+ return true if force == text || ENV [ 'FORCE' ] == text
610
+ end
611
+ return false
612
+ end
613
+
601
614
def update_files_in_repos ( purpose , suffix = '' , opts = { } )
602
615
suffix = [ BASE_BRANCH , ENV [ 'BRANCH_SUFFIX' ] ] . compact . join ( '-' )
603
616
branch_name = "update-#{ purpose . gsub ' ' , '-' } -#{ ENV . fetch ( 'BRANCH_DATE' , Date . today . iso8601 ) } -for-#{ suffix } "
@@ -612,7 +625,7 @@ def update_files_in_repos(purpose, suffix='', opts={})
612
625
end
613
626
614
627
each_project_with_common_build ( opts ) do |name |
615
- branch_name = confirm_branch_name ( branch_name )
628
+ branch_name = confirm_branch_name ( branch_name , opts )
616
629
sh "git checkout -b #{ branch_name } "
617
630
618
631
yield name
0 commit comments