Skip to content

Commit

Permalink
Merge pull request prontolabs#40 from splattael/git-index
Browse files Browse the repository at this point in the history
Analyze changes in git index using "-i" option
  • Loading branch information
mmozuras committed Oct 27, 2014
2 parents 9087be0 + 7dbba9c commit 99147b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

* 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.

## 0.3.3

Expand Down
8 changes: 7 additions & 1 deletion lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def is_thor_reserved_word?(word, type)
aliases: '-c',
banner: 'Commit for the diff'

method_option :index,
type: :boolean,
aliases: '-i',
banner: 'Analyze changes in git index (staging area)'

method_option :runner,
type: :array,
default: [],
Expand All @@ -43,7 +48,8 @@ def run
end

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

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

def show_commit(sha)
Expand Down

0 comments on commit 99147b2

Please sign in to comment.