Skip to content

Commit

Permalink
Support the match option
Browse files Browse the repository at this point in the history
  • Loading branch information
betesh committed Apr 30, 2020
1 parent b5d64d4 commit 7cfe77d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/rjgit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,18 @@ def self.diff(repository, options = {})
end

def self.describe(repository, ref, options = {})
options = {:always => false, :long => false, :tags => false}.merge(options)
options = {:always => false, :long => false, :tags => false, :match => []}.merge(options)
repo = RJGit.repository_type(repository)
git = RubyGit.new(repo).jgit
git.describe.set_target(ref).set_always(options[:always]).set_long(options[:long]).set_tags(options[:tags]).call
command = git.describe.
set_target(ref).
set_always(options[:always]).
set_long(options[:long]).
set_tags(options[:tags])
command = options[:match].each_with_object(command) do |match|
command.set_match(match)
end
command.call
end
end

Expand Down
16 changes: 13 additions & 3 deletions spec/rjgit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,19 @@
end
end

it "mimics git-describe" do
id = Porcelain.commit(@repo, "Initial commit").id
expect(Porcelain.describe(@repo, id)).to match(/\Av0\.0-2-g[0-9a-f]{7}\z/)
describe 'git-describe' do
it "mimics git-describe" do
id = Porcelain.commit(@repo, "Initial commit").id
expect(Porcelain.describe(@repo, id)).to match(/\Av0\.0-2-g[0-9a-f]{7}\z/)
end

it "matches the right tag when match is used" do
@repo.git.tag('v0.1', 'Tag v0.1', Porcelain.commit(@repo, "Previous commit").id)
id = Porcelain.commit(@repo, "Initial commit").id
expect(Porcelain.describe(@repo, id, match: ['v0.0'])).to match(/\Av0\.0-4-g[0-9a-f]{7}\z/)
expect(Porcelain.describe(@repo, id, match: ['v0.1'])).to match(/\Av0\.1-1-g[0-9a-f]{7}\z/)
expect(Porcelain.describe(@repo, id, match: ['v0.0', 'v0.1'])).to match(/\Av0\.1-1-g[0-9a-f]{7}\z/)
end
end

after(:all) do
Expand Down

0 comments on commit 7cfe77d

Please sign in to comment.