Skip to content

Commit 174a893

Browse files
committed
Add --workdir option
Allows for both staged and unstaged files to be checked.
1 parent 999d0b9 commit 174a893

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/pronto/cli.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def is_thor_reserved_word?(word, type)
3333
type: :boolean,
3434
desc: 'Analyze changes in git staging area'
3535

36+
method_option :workdir,
37+
type: :boolean,
38+
aliases: ['-w'],
39+
desc: 'Analyze both staged and unstaged changes'
40+
3641
method_option :runner,
3742
type: :array,
3843
default: [],
@@ -55,7 +60,7 @@ def run(path = '.')
5560

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

58-
commit_options = %i[staged unstaged index]
63+
commit_options = %i[workdir staged unstaged index]
5964
commit = commit_options.find { |o| options[o] } || options[:commit]
6065

6166
repo_workdir = ::Rugged::Repository.discover(path).workdir

lib/pronto/git/repository.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ def diff(commit, options = nil)
1313
[head_commit_sha, @repo.index.diff(options)]
1414
when :staged
1515
[head_commit_sha, head.diff(@repo.index, options)]
16+
when :workdir
17+
[
18+
head_commit_sha,
19+
@repo.diff_workdir(
20+
head,
21+
{
22+
include_untracked: true,
23+
include_untracked_content: true,
24+
recurse_untracked_dirs: true
25+
}.merge(options || {})
26+
)
27+
]
1628
else
1729
merge_base = merge_base(commit)
1830
patches = @repo.diff(merge_base, head, options)

spec/pronto/git/repository_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ module Git
9292
let(:sha) { :staged }
9393
it { should be_one }
9494
end
95+
96+
context 'workdir' do
97+
let(:sha) { :workdir }
98+
99+
it do
100+
# this count includes all the files from the repositories (*.git)
101+
subject.count.should eq 48
102+
end
103+
end
95104
end
96105

97106
describe '#blame' do

0 commit comments

Comments
 (0)