Skip to content

Commit df3b07d

Browse files
committed
feat: make Git::Log support the git log --merges option
1 parent a832259 commit df3b07d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

lib/git/lib.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def log_commits(opts = {})
294294
# * 'tree' [String] the tree sha
295295
# * 'author' [String] the author of the commit and timestamp of when the changes were created
296296
# * 'committer' [String] the committer of the commit and timestamp of when the commit was applied
297+
# * 'merges' [Boolean] if truthy, only include merge commits (aka commits with 2 or more parents)
297298
#
298299
# @raise [ArgumentError] if the revision range (specified with :between or :object) is a string starting with a hyphen
299300
#
@@ -305,6 +306,7 @@ def full_log_commits(opts = {})
305306

306307
arr_opts << '--pretty=raw'
307308
arr_opts << "--skip=#{opts[:skip]}" if opts[:skip]
309+
arr_opts << '--merges' if opts[:merges]
308310

309311
arr_opts += log_path_options(opts)
310312

lib/git/log.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ def cherry
133133
return self
134134
end
135135

136+
def merges
137+
dirty_log
138+
@merges = true
139+
return self
140+
end
141+
136142
def to_s
137143
self.map { |c| c.to_s }.join("\n")
138144
end
139145

140-
141146
# forces git log to run
142147

143148
def size
@@ -184,7 +189,7 @@ def run_log
184189
log = @base.lib.full_log_commits(
185190
count: @max_count, all: @all, object: @object, path_limiter: @path, since: @since,
186191
author: @author, grep: @grep, skip: @skip, until: @until, between: @between,
187-
cherry: @cherry
192+
cherry: @cherry, merges: @merges
188193
)
189194
@commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
190195
end

tests/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def append_file(name, contents)
131131
#
132132
# @return [void]
133133
#
134-
def assert_command_line_eq(expected_command_line, method: :command, mocked_output: nil, include_env: false)
134+
def assert_command_line_eq(expected_command_line, method: :command, mocked_output: '', include_env: false)
135135
actual_command_line = nil
136136

137137
command_output = ''

tests/units/test_log.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,9 @@ def test_log_cherry
128128
l = @git.log.between( 'master', 'cherry').cherry
129129
assert_equal( 1, l.size )
130130
end
131+
132+
def test_log_merges
133+
expected_command_line = ['log', '--max-count=30', '--no-color', '--pretty=raw', '--merges', {:chdir=>nil}]
134+
assert_command_line_eq(expected_command_line) { |git| git.log.merges.size }
135+
end
131136
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy