Skip to content

Commit 0593e4f

Browse files
authored
Add no-ff merge option. (ruby-git#471)
Signed-off-by: hokita <hideee.0202@gmail.com>
1 parent b2f8845 commit 0593e4f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ g.branch(branch2).merge # merges HEAD with branch2
223223

224224
g.branch(name).in_branch(message) { # add files } # auto-commits
225225
g.merge('new_branch')
226+
g.merge('new_branch', 'merge commit message', no_ff: true)
226227
g.merge('origin/remote_branch')
227228
g.merge(g.branch('master'))
228229
g.merge([branch1, branch2])

lib/git/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def push(remote = 'origin', branch = 'master', opts = {})
347347
# merges one or more branches into the current working branch
348348
#
349349
# you can specify more than one branch to merge by passing an array of branches
350-
def merge(branch, message = 'merge')
351-
self.lib.merge(branch, message)
350+
def merge(branch, message = 'merge', opts = {})
351+
self.lib.merge(branch, message, opts)
352352
end
353353

354354
# iterates over the files which are unmerged

lib/git/lib.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ def checkout_file(version, file)
714714
command('checkout', arr_opts)
715715
end
716716

717-
def merge(branch, message = nil)
717+
def merge(branch, message = nil, opts = {})
718718
arr_opts = []
719+
arr_opts << '--no-ff' if opts[:no_ff]
719720
arr_opts << '-m' << message if message
720721
arr_opts += [branch]
721722
command('merge', arr_opts)

tests/units/test_merge.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,33 @@ def test_branch_and_merge_multiple
101101
end
102102
end
103103

104-
end
104+
def test_no_ff_merge
105+
in_temp_dir do |path|
106+
g = Git.clone(@wbare, 'branch_merge_test')
107+
Dir.chdir('branch_merge_test') do
108+
109+
g.branch('new_branch').in_branch('first commit message') do
110+
new_file('new_file_1', 'hello')
111+
g.add
112+
true
113+
end
114+
115+
g.branch('new_branch2').checkout
116+
g.merge('new_branch', 'merge commit message') # ff merge
117+
assert(g.status['new_file_1']) # file has been merged in
118+
assert_equal('first commit message', g.log.first.message) # merge commit message was ignored
119+
120+
g.branch('new_branch').in_branch('second commit message') do
121+
new_file('new_file_2', 'hello')
122+
g.add
123+
true
124+
end
125+
126+
assert_equal('new_branch2', g.current_branch) # still in new_branch2 branch
127+
g.merge('new_branch', 'merge commit message', no_ff: true) # no-ff merge
128+
assert(g.status['new_file_2']) # file has been merged in
129+
assert_equal('merge commit message', g.log.first.message)
130+
end
131+
end
132+
end
133+
end

0 commit comments

Comments
 (0)