File tree 4 files changed +20
-1
lines changed
4 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,9 @@ def self.global_config(name = nil, value = nil)
212
212
# `"#{directory}/.git"`, create a bare repository at `"#{directory}"`.
213
213
# See [what is a bare repository?](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbarerepositoryabarerepository).
214
214
#
215
+ # @option options [String] :initial_branch Use the specified name for the
216
+ # initial branch in the newly created repository.
217
+ #
215
218
# @option options [Pathname] :repository the path to put the newly initialized
216
219
# Git repository. The default for non-bare repository is `"#{directory}/.git"`.
217
220
#
Original file line number Diff line number Diff line change @@ -34,7 +34,10 @@ def self.init(directory, options = {})
34
34
35
35
FileUtils . mkdir_p ( options [ :working_directory ] ) if options [ :working_directory ] && !File . directory? ( options [ :working_directory ] )
36
36
37
- init_options = { :bare => options [ :bare ] }
37
+ init_options = {
38
+ :bare => options [ :bare ] ,
39
+ :initial_branch => options [ :initial_branch ] ,
40
+ }
38
41
39
42
options . delete ( :working_directory ) if options [ :bare ]
40
43
Original file line number Diff line number Diff line change @@ -71,10 +71,12 @@ def initialize(base = nil, logger = nil)
71
71
# options:
72
72
# :bare
73
73
# :working_directory
74
+ # :initial_branch
74
75
#
75
76
def init ( opts = { } )
76
77
arr_opts = [ ]
77
78
arr_opts << '--bare' if opts [ :bare ]
79
+ arr_opts << "--initial-branch=#{ opts [ :initial_branch ] } " if opts [ :initial_branch ]
78
80
79
81
command ( 'init' , arr_opts )
80
82
end
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ def test_git_init
38
38
assert ( File . directory? ( File . join ( path , '.git' ) ) )
39
39
assert ( File . exist? ( File . join ( path , '.git' , 'config' ) ) )
40
40
assert_equal ( 'false' , repo . config ( 'core.bare' ) )
41
+ assert_equal ( "ref: refs/heads/master\n " , File . read ( "#{ path } /.git/HEAD" ) )
41
42
end
42
43
end
43
44
@@ -61,6 +62,16 @@ def test_git_init_remote_git
61
62
end
62
63
end
63
64
65
+ def test_git_init_initial_branch
66
+ in_temp_dir do |path |
67
+ repo = Git . init ( path , initial_branch : 'main' )
68
+ assert ( File . directory? ( File . join ( path , '.git' ) ) )
69
+ assert ( File . exist? ( File . join ( path , '.git' , 'config' ) ) )
70
+ assert_equal ( 'false' , repo . config ( 'core.bare' ) )
71
+ assert_equal ( "ref: refs/heads/main\n " , File . read ( "#{ path } /.git/HEAD" ) )
72
+ end
73
+ end
74
+
64
75
def test_git_clone
65
76
in_temp_dir do |path |
66
77
g = Git . clone ( @wbare , 'bare-co' )
You can’t perform that action at this time.
0 commit comments