File tree Expand file tree Collapse file tree 5 files changed +17
-6
lines changed Expand file tree Collapse file tree 5 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -529,8 +529,13 @@ def using_bun?
529
529
using_js_runtime? && %w[ bun ] . include? ( options [ :javascript ] )
530
530
end
531
531
532
- def capture_command ( command , pattern )
533
- `#{ command } ` [ pattern ]
532
+ def capture_command ( command , pattern = nil )
533
+ output = `#{ command } `
534
+ if pattern
535
+ output [ pattern ]
536
+ else
537
+ output
538
+ end
534
539
rescue SystemCallError
535
540
nil
536
541
end
@@ -760,11 +765,13 @@ def keep_file(destination)
760
765
end
761
766
762
767
def user_default_branch
763
- @user_default_branch ||= ` git config init.defaultbranch`
768
+ @user_default_branch ||= capture_command ( " git config init.defaultbranch" ) . strip . presence || "main"
764
769
end
765
770
766
771
def git_init_command
767
- return "git init" if user_default_branch . strip . present?
772
+ if capture_command ( "git config init.defaultbranch" ) . present?
773
+ return "git init"
774
+ end
768
775
769
776
git_version = `git --version` [ /\d +\. \d +\. \d +/ ]
770
777
Original file line number Diff line number Diff line change 3
3
on:
4
4
pull_request:
5
5
push:
6
- branches: [ main ]
6
+ branches: [ <%= user_default_branch %> ]
7
7
8
8
jobs:
9
9
<%- unless skip_brakeman? -%>
Original file line number Diff line number Diff line change 3
3
on:
4
4
pull_request:
5
5
push:
6
- branches: [ main ]
6
+ branches: [ <%= user_default_branch %> ]
7
7
8
8
jobs:
9
9
<%- unless skip_rubocop? -%>
Original file line number Diff line number Diff line change @@ -1150,6 +1150,7 @@ def test_default_branch_main_without_user_default
1150
1150
1151
1151
run_generator [ destination_root ]
1152
1152
assert_file ".git/HEAD" , /main/
1153
+ assert_file ".github/workflows/ci.yml" , /branches: \[ main \] /
1153
1154
ensure
1154
1155
if !current_default_branch . strip . empty?
1155
1156
`git config --global init.defaultBranch #{ current_default_branch } `
@@ -1165,6 +1166,7 @@ def test_version_control_initializes_git_repo_with_user_default_branch
1165
1166
1166
1167
run_generator [ destination_root ]
1167
1168
assert_file ".git/HEAD" , /master/
1169
+ assert_file ".github/workflows/ci.yml" , /branches: \[ master \] /
1168
1170
ensure
1169
1171
if current_default_branch && current_default_branch . strip . empty?
1170
1172
`git config --global --unset init.defaultBranch`
Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ def test_initializes_git_repo_with_main_branch_without_user_default
145
145
146
146
run_generator
147
147
assert_file ".git/HEAD" , /main/
148
+ assert_file ".github/workflows/ci.yml" , /branches: \[ main \] /
148
149
ensure
149
150
if !current_default_branch . strip . empty?
150
151
`git config --global init.defaultBranch #{ current_default_branch } `
@@ -160,6 +161,7 @@ def test_version_control_initializes_git_repo_with_user_default_branch
160
161
161
162
run_generator
162
163
assert_file ".git/HEAD" , /master/
164
+ assert_file ".github/workflows/ci.yml" , /branches: \[ master \] /
163
165
ensure
164
166
if current_default_branch && current_default_branch . strip . empty?
165
167
`git config --global --unset init.defaultBranch`
You can’t perform that action at this time.
0 commit comments