Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying a path on which to pronto run #52

Merged
merged 1 commit into from
Nov 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Try to detect pull request id automatically, if `PULL_REQUEST_ID` is not specified. Inspired by @willnet/prid.
* [#40](https://github.com/mmozuras/pronto/issues/40): Add '--index' option for 'pronto run'. Pronto analyzes changes before committing.
* [#50](https://github.com/mmozuras/pronto/pull/50): Adds GitLab formatter
* [#52](https://github.com/mmozuras/pronto/pull/52): Allow specifying a path for 'pronto run'.

### Changes
* Github and Github pull request formatters now filter out duplicate offenses on the same line to avoid spamming with redundant comments.
Expand Down
11 changes: 4 additions & 7 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
require 'pronto/formatter/formatter'

module Pronto
def self.run(commit = 'master', repo_path = '.', formatter = nil)
def self.run(commit = 'master', repo_path = '.',
formatter = Formatter::TextFormatter.new, file = nil)
commit ||= 'master'

repo = Git::Repository.new(repo_path)
patches = repo.diff(commit)
options = { paths: [file] } if file
patches = repo.diff(commit, options)

result = run_all_runners(patches)

formatter ||= default_formatter
puts formatter.format(result, repo)

result
Expand Down Expand Up @@ -59,8 +60,4 @@ def self.run_all_runners(patches)
runner.new.run(patches, patches.commit)
end.flatten.compact
end

def default_formatter
Formatter::TextFormatter.new
end
end
4 changes: 2 additions & 2 deletions lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def is_thor_reserved_word?(word, type)
aliases: '-f',
banner: "Pick output formatter. Available: #{::Pronto::Formatter.names.join(', ')}"

def run
def run(path = nil)
gem_names = options[:runner].any? ? options[:runner] : ::Pronto.gem_names
gem_names.each do |gem_name|
require "pronto/#{gem_name}"
end

formatter = ::Pronto::Formatter.get(options[:formatter])
commit = options[:index] ? :index : options[:commit]
messages = ::Pronto.run(commit, '.', formatter)
messages = ::Pronto.run(commit, '.', formatter, path)
exit(messages.count) if options[:'exit-code']
rescue Rugged::RepositoryError
puts '"pronto" should be run from a git repository'
Expand Down
6 changes: 3 additions & 3 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def initialize(path)
@repo = Rugged::Repository.new(path)
end

def diff(commit)
def diff(commit, options = nil)
if commit == :index
patches = @repo.index.diff
patches = @repo.index.diff(options)
Patches.new(self, head, patches)
else
merge_base = merge_base(commit)
patches = @repo.diff(merge_base, head)
patches = @repo.diff(merge_base, head, options)
Patches.new(self, merge_base, patches)
end
end
Expand Down