Skip to content

Commit a25eb1a

Browse files
authored
Add cherry support to Git::Log (#97)
Signed-off-by: Peter Kovacs <peter@sanebox.com>
1 parent 181ace3 commit a25eb1a

File tree

11 files changed

+27
-3
lines changed

11 files changed

+27
-3
lines changed

lib/git/lib.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ def log_common_options(opts)
11001100

11011101
arr_opts << "-#{opts[:count]}" if opts[:count]
11021102
arr_opts << "--no-color"
1103+
arr_opts << "--cherry" if opts[:cherry]
11031104
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
11041105
arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String
11051106
arr_opts << "--grep=#{opts[:grep]}" if opts[:grep].is_a? String

lib/git/log.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def initialize(base, count = 30)
1818
@skip = nil
1919
@until = nil
2020
@between = nil
21+
@cherry = nil
2122
end
2223

2324
def object(objectish)
@@ -67,6 +68,12 @@ def between(sha1, sha2 = nil)
6768
@between = [sha1, sha2]
6869
return self
6970
end
71+
72+
def cherry
73+
dirty_log
74+
@cherry = true
75+
return self
76+
end
7077

7178
def to_s
7279
self.map { |c| c.to_s }.join("\n")
@@ -119,7 +126,7 @@ def run_log
119126
log = @base.lib.full_log_commits(:count => @count, :object => @object,
120127
:path_limiter => @path, :since => @since,
121128
:author => @author, :grep => @grep, :skip => @skip,
122-
:until => @until, :between => @between)
129+
:until => @until, :between => @between, :cherry => @cherry)
123130
@commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
124131
end
125132

tests/files/working/dot_git/index

-94 Bytes
Binary file not shown.

tests/files/working/dot_git/logs/HEAD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,9 @@ b98f4909807c8c84a1dc1b62b4a339ae1777f369 87c56502c73149f006631129f85dff697e00035
7373
a3db7143944dcfa006fefe7fb49c48793cb29ade 34a566d193dc4702f03149969a2aad1443231560 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194632975 -0800 commit: modified to not show up
7474
34a566d193dc4702f03149969a2aad1443231560 935badc874edd62a8629aaf103418092c73f0a56 scott Chacon <schacon@agadorsparticus.corp.reactrix.com> 1194633382 -0800 commit: more search help
7575
935badc874edd62a8629aaf103418092c73f0a56 5e53019b3238362144c2766f02a2c00d91fcc023 scott Chacon <schacon@agadorsparticus.(none)> 1194720731 -0800 commit: diff test
76+
5e53019b3238362144c2766f02a2c00d91fcc023 5e392652a881999392c2757cf9b783c5d47b67f7 Scott Chacon <schacon@gmail.com> 1378909802 -0400 checkout: moving from git_grep to master
77+
5e392652a881999392c2757cf9b783c5d47b67f7 545c81a2e8d1112d5f7356f840a22e8f6abcef8f Scott Chacon <schacon@gmail.com> 1378910044 -0400 checkout: moving from master to cherry
78+
545c81a2e8d1112d5f7356f840a22e8f6abcef8f 6f09de178a27f7702c37907fd614c3c122d33c30 Scott Chacon <schacon@gmail.com> 1378910061 -0400 commit: in cherry
79+
6f09de178a27f7702c37907fd614c3c122d33c30 faf8d899a0f123c3c5def10857920be1c930e8ed Scott Chacon <schacon@gmail.com> 1378910110 -0400 commit (merge): Merge commit '4ce44a75510cbfe200b131fdbcc56a86f1b2dc08' into cherry
80+
faf8d899a0f123c3c5def10857920be1c930e8ed 5e392652a881999392c2757cf9b783c5d47b67f7 Scott Chacon <schacon@gmail.com> 1378910135 -0400 checkout: moving from cherry to master
81+
5e392652a881999392c2757cf9b783c5d47b67f7 5e53019b3238362144c2766f02a2c00d91fcc023 Scott Chacon <schacon@gmail.com> 1378910138 -0400 checkout: moving from master to git_grep
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0000000000000000000000000000000000000000 545c81a2e8d1112d5f7356f840a22e8f6abcef8f Scott Chacon <schacon@gmail.com> 1378910044 -0400 branch: Created from 545c81a2e8d1112d5f7356f840a22e8f6abcef8f
2+
545c81a2e8d1112d5f7356f840a22e8f6abcef8f 6f09de178a27f7702c37907fd614c3c122d33c30 Scott Chacon <schacon@gmail.com> 1378910061 -0400 commit: in cherry
3+
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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
faf8d899a0f123c3c5def10857920be1c930e8ed

tests/units/test_log.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@ def test_log_with_empty_commit_message
9191
assert_equal(expected_message, log[1].message)
9292
end
9393
end
94+
95+
def test_log_cherry
96+
l = @git.log.between( 'master', 'cherry').cherry
97+
assert_equal( 1, l.size )
98+
end
99+
94100
end

tests/units/test_logger.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_logger
2020

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

2525
log = Tempfile.new('logfile')
2626
log.close
@@ -32,7 +32,7 @@ def test_logger
3232

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

3838
end

0 commit comments

Comments
 (0)