File tree 6 files changed +52
-1
lines changed
6 files changed +52
-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
@@ -786,6 +788,7 @@ def checkout_file(version, file)
786
788
787
789
def merge ( branch , message = nil , opts = { } )
788
790
arr_opts = [ ]
791
+ arr_opts << '--no-commit' if opts [ :no_commit ]
789
792
arr_opts << '--no-ff' if opts [ :no_ff ]
790
793
arr_opts << '-m' << message if message
791
794
arr_opts += [ branch ]
@@ -893,6 +896,7 @@ def fetch(remote, opts)
893
896
arr_opts << '--tags' if opts [ :t ] || opts [ :tags ]
894
897
arr_opts << '--prune' if opts [ :p ] || opts [ :prune ]
895
898
arr_opts << '--unshallow' if opts [ :unshallow ]
899
+ arr_opts << '--depth' << opts [ :depth ] if opts [ :depth ]
896
900
897
901
command ( 'fetch' , arr_opts )
898
902
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' )
Original file line number Diff line number Diff line change @@ -130,4 +130,33 @@ def test_no_ff_merge
130
130
end
131
131
end
132
132
end
133
+
134
+ def test_merge_no_commit
135
+ in_temp_dir do |path |
136
+ g = Git . clone ( @wbare , 'branch_merge_test' )
137
+ g . chdir do
138
+ g . branch ( 'new_branch_1' ) . in_branch ( 'first commit message' ) do
139
+ new_file ( 'new_file_1' , 'foo' )
140
+ g . add
141
+ true
142
+ end
143
+
144
+ g . branch ( 'new_branch_2' ) . in_branch ( 'first commit message' ) do
145
+ new_file ( 'new_file_2' , 'bar' )
146
+ g . add
147
+ true
148
+ end
149
+
150
+ g . checkout ( 'new_branch_2' )
151
+ before_merge = g . show
152
+ g . merge ( 'new_branch_1' , nil , no_commit : true )
153
+ # HEAD is the same as before.
154
+ assert_equal ( before_merge , g . show )
155
+ # File has not been merged in.
156
+ status = g . status [ 'new_file_1' ]
157
+ assert_equal ( 'new_file_1' , status . path )
158
+ assert_equal ( 'A' , status . type )
159
+ end
160
+ end
161
+ end
133
162
end
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
2
require 'fileutils'
3
+ require 'pathname'
3
4
require File . dirname ( __FILE__ ) + '/../test_helper'
4
5
5
6
SAMPLE_LAST_COMMIT = '5e53019b3238362144c2766f02a2c00d91fcc023'
You can’t perform that action at this time.
0 commit comments