Skip to content

Commit

Permalink
Add --workdir option
Browse files Browse the repository at this point in the history
Allows for both staged and unstaged files to be checked.
  • Loading branch information
tylerhunt committed Mar 16, 2021
1 parent 999d0b9 commit 330fa5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pronto/cli.rb
Expand Up @@ -33,6 +33,11 @@ def is_thor_reserved_word?(word, type)
type: :boolean,
desc: 'Analyze changes in git staging area'

method_option :workdir,
type: :boolean,
aliases: ['-w'],
desc: 'Analyze both staged and unstaged changes'

method_option :runner,
type: :array,
default: [],
Expand All @@ -55,7 +60,7 @@ def run(path = '.')

formatters = ::Pronto::Formatter.get(options[:formatters])

commit_options = %i[staged unstaged index]
commit_options = %i[staged unstaged index workdir]
commit = commit_options.find { |o| options[o] } || options[:commit]

repo_workdir = ::Rugged::Repository.discover(path).workdir
Expand Down
12 changes: 12 additions & 0 deletions lib/pronto/git/repository.rb
Expand Up @@ -13,6 +13,18 @@ def diff(commit, options = nil)
[head_commit_sha, @repo.index.diff(options)]
when :staged
[head_commit_sha, head.diff(@repo.index, options)]
when :workdir
[
head_commit_sha,
@repo.diff_workdir(
head,
{
include_untracked: true,
include_untracked_content: true,
recurse_untracked_dirs: true,
}.merge(options || {})
)
]
else
merge_base = merge_base(commit)
patches = @repo.diff(merge_base, head, options)
Expand Down
5 changes: 5 additions & 0 deletions spec/pronto/git/repository_spec.rb
Expand Up @@ -92,6 +92,11 @@ module Git
let(:sha) { :staged }
it { should be_one }
end

context 'workdir' do
let(:sha) { :workdir }
it { subject.count.should eq 48 }
end
end

describe '#blame' do
Expand Down

0 comments on commit 330fa5b

Please sign in to comment.