diff --git a/lib/git/lib.rb b/lib/git/lib.rb index b62d69c1..692ceef9 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -294,6 +294,7 @@ def log_commits(opts = {}) # * 'tree' [String] the tree sha # * 'author' [String] the author of the commit and timestamp of when the changes were created # * 'committer' [String] the committer of the commit and timestamp of when the commit was applied + # * 'merges' [Boolean] if truthy, only include merge commits (aka commits with 2 or more parents) # # @raise [ArgumentError] if the revision range (specified with :between or :object) is a string starting with a hyphen # @@ -305,6 +306,7 @@ def full_log_commits(opts = {}) arr_opts << '--pretty=raw' arr_opts << "--skip=#{opts[:skip]}" if opts[:skip] + arr_opts << '--merges' if opts[:merges] arr_opts += log_path_options(opts) diff --git a/lib/git/log.rb b/lib/git/log.rb index dad2c2cd..7ac31622 100644 --- a/lib/git/log.rb +++ b/lib/git/log.rb @@ -133,11 +133,16 @@ def cherry return self end + def merges + dirty_log + @merges = true + return self + end + def to_s self.map { |c| c.to_s }.join("\n") end - # forces git log to run def size @@ -184,7 +189,7 @@ def run_log log = @base.lib.full_log_commits( count: @max_count, all: @all, object: @object, path_limiter: @path, since: @since, author: @author, grep: @grep, skip: @skip, until: @until, between: @between, - cherry: @cherry + cherry: @cherry, merges: @merges ) @commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) } end diff --git a/tests/test_helper.rb b/tests/test_helper.rb index 067fa633..f35a0fcd 100644 --- a/tests/test_helper.rb +++ b/tests/test_helper.rb @@ -131,7 +131,7 @@ def append_file(name, contents) # # @return [void] # - def assert_command_line_eq(expected_command_line, method: :command, mocked_output: nil, include_env: false) + def assert_command_line_eq(expected_command_line, method: :command, mocked_output: '', include_env: false) actual_command_line = nil command_output = '' diff --git a/tests/units/test_log.rb b/tests/units/test_log.rb index 1cab1a32..f18fabf2 100644 --- a/tests/units/test_log.rb +++ b/tests/units/test_log.rb @@ -128,4 +128,9 @@ def test_log_cherry l = @git.log.between( 'master', 'cherry').cherry assert_equal( 1, l.size ) end + + def test_log_merges + expected_command_line = ['log', '--max-count=30', '--no-color', '--pretty=raw', '--merges', {:chdir=>nil}] + assert_command_line_eq(expected_command_line) { |git| git.log.merges.size } + end end