Skip to content

Commit

Permalink
Add cherry support to Git::Log (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Kovacs <peter@sanebox.com>
  • Loading branch information
peterkovacs committed Dec 23, 2020
1 parent 181ace3 commit a25eb1a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ def log_common_options(opts)

arr_opts << "-#{opts[:count]}" if opts[:count]
arr_opts << "--no-color"
arr_opts << "--cherry" if opts[:cherry]
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String
arr_opts << "--grep=#{opts[:grep]}" if opts[:grep].is_a? String
Expand Down
9 changes: 8 additions & 1 deletion lib/git/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(base, count = 30)
@skip = nil
@until = nil
@between = nil
@cherry = nil
end

def object(objectish)
Expand Down Expand Up @@ -67,6 +68,12 @@ def between(sha1, sha2 = nil)
@between = [sha1, sha2]
return self
end

def cherry
dirty_log
@cherry = true
return self
end

def to_s
self.map { |c| c.to_s }.join("\n")
Expand Down Expand Up @@ -119,7 +126,7 @@ def run_log
log = @base.lib.full_log_commits(:count => @count, :object => @object,
:path_limiter => @path, :since => @since,
:author => @author, :grep => @grep, :skip => @skip,
:until => @until, :between => @between)
:until => @until, :between => @between, :cherry => @cherry)
@commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
end

Expand Down
Binary file modified tests/files/working/dot_git/index
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/files/working/dot_git/logs/HEAD
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ b98f4909807c8c84a1dc1b62b4a339ae1777f369 87c56502c73149f006631129f85dff697e00035
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
5e53019b3238362144c2766f02a2c00d91fcc023 5e392652a881999392c2757cf9b783c5d47b67f7 Scott Chacon <schacon@gmail.com> 1378909802 -0400 checkout: moving from git_grep to master
5e392652a881999392c2757cf9b783c5d47b67f7 545c81a2e8d1112d5f7356f840a22e8f6abcef8f Scott Chacon <schacon@gmail.com> 1378910044 -0400 checkout: moving from master to cherry
545c81a2e8d1112d5f7356f840a22e8f6abcef8f 6f09de178a27f7702c37907fd614c3c122d33c30 Scott Chacon <schacon@gmail.com> 1378910061 -0400 commit: in cherry
6f09de178a27f7702c37907fd614c3c122d33c30 faf8d899a0f123c3c5def10857920be1c930e8ed Scott Chacon <schacon@gmail.com> 1378910110 -0400 commit (merge): Merge commit '4ce44a75510cbfe200b131fdbcc56a86f1b2dc08' into cherry
faf8d899a0f123c3c5def10857920be1c930e8ed 5e392652a881999392c2757cf9b783c5d47b67f7 Scott Chacon <schacon@gmail.com> 1378910135 -0400 checkout: moving from cherry to master
5e392652a881999392c2757cf9b783c5d47b67f7 5e53019b3238362144c2766f02a2c00d91fcc023 Scott Chacon <schacon@gmail.com> 1378910138 -0400 checkout: moving from master to git_grep
3 changes: 3 additions & 0 deletions tests/files/working/dot_git/logs/refs/heads/cherry
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 545c81a2e8d1112d5f7356f840a22e8f6abcef8f Scott Chacon <schacon@gmail.com> 1378910044 -0400 branch: Created from 545c81a2e8d1112d5f7356f840a22e8f6abcef8f
545c81a2e8d1112d5f7356f840a22e8f6abcef8f 6f09de178a27f7702c37907fd614c3c122d33c30 Scott Chacon <schacon@gmail.com> 1378910061 -0400 commit: in cherry
6f09de178a27f7702c37907fd614c3c122d33c30 faf8d899a0f123c3c5def10857920be1c930e8ed Scott Chacon <schacon@gmail.com> 1378910110 -0400 commit (merge): Merge commit '4ce44a75510cbfe200b131fdbcc56a86f1b2dc08' into cherry
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/files/working/dot_git/refs/heads/cherry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
faf8d899a0f123c3c5def10857920be1c930e8ed
6 changes: 6 additions & 0 deletions tests/units/test_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ def test_log_with_empty_commit_message
assert_equal(expected_message, log[1].message)
end
end

def test_log_cherry
l = @git.log.between( 'master', 'cherry').cherry
assert_equal( 1, l.size )
end

end
4 changes: 2 additions & 2 deletions tests/units/test_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_logger

logc = File.read(log.path)
assert(/INFO -- : git ['"]--git-dir=[^'"]+['"] ['"]--work-tree=[^'"]+['"] ['"]-c['"] ['"]color.ui=false['"] branch ['"]-a['"]/.match(logc))
assert(/DEBUG -- : diff_over_patches/.match(logc))
assert(/DEBUG -- : cherry\n diff_over_patches\n\* git_grep/m.match(logc))

log = Tempfile.new('logfile')
log.close
Expand All @@ -32,7 +32,7 @@ def test_logger

logc = File.read(log.path)
assert(/INFO -- : git ['"]--git-dir=[^'"]+['"] ['"]--work-tree=[^'"]+['"] ['"]-c['"] ['"]color.ui=false['"] branch ['"]-a['"]/.match(logc))
assert(!/DEBUG -- : diff_over_patches/.match(logc))
assert(!/DEBUG -- : cherry\n diff_over_patches\n\* git_grep/m.match(logc))
end

end

0 comments on commit a25eb1a

Please sign in to comment.