diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ac7c3f..2fcc978d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/pronto/cli.rb b/lib/pronto/cli.rb index a839d8d4..135f4f43 100644 --- a/lib/pronto/cli.rb +++ b/lib/pronto/cli.rb @@ -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: [], @@ -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' diff --git a/lib/pronto/git/repository.rb b/lib/pronto/git/repository.rb index f7e59cd5..3e58762f 100644 --- a/lib/pronto/git/repository.rb +++ b/lib/pronto/git/repository.rb @@ -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)