File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ def start
3535 # @return [Object] the task result
3636 def run_all
3737 return warn_codespell_missing unless codespell
38+ return run_codespell ( changed_files ) if options [ :only_git_changes ]
3839
3940 run_codespell
4041 end
@@ -66,8 +67,9 @@ def run_on_modifications(paths)
6667 def run_codespell ( paths = [ ] )
6768 Guard ::Compat ::UI . info "Looking for typos with codespell"
6869 cmd = build_command ( paths )
69- Guard ::Compat ::UI . info "... running #{ cmd } "
70+ Guard ::Compat ::UI . info "... running #{ cmd } " if options [ :debug ]
7071 system ( cmd )
72+ Guard ::Compat ::UI . info "Codespell check finished"
7173 end
7274
7375 def build_command ( paths )
@@ -95,5 +97,12 @@ def warn_codespell_missing
9597 Guard ::Compat ::UI . warning "Spellcheck failed - guard-codespell cannot find the codespell library."
9698 Guard ::Compat ::UI . warning "Please run `pip install codespell` to resolve this issue."
9799 end
100+
101+ # Fetch a list of changed files from the result of git status
102+ def changed_files
103+ `git status --porcelain` . lines . map do |line |
104+ line . chomp . split ( " " ) . last
105+ end
106+ end
98107 end
99108end
Original file line number Diff line number Diff line change 44require "guard/codespell"
55
66RSpec . describe Guard ::Codespell do
7- subject ( :guard ) { described_class . new ( { } ) }
7+ subject ( :guard ) { described_class . new ( options ) }
88
99 let ( :paths ) { %w[ path/to/foo.rb path/to/bar/baz.js ] }
10+ let ( :options ) { { } }
1011
1112 before do
1213 allow ( guard ) . to receive ( :run_codespell )
3940 guard . run_all
4041 expect ( guard ) . to have_received ( :run_codespell ) . with ( no_args )
4142 end
43+
44+ context "when only_git_changes option is set to true" do
45+ let ( :options ) { { only_git_changes : true } }
46+
47+ it "calls run_codespell without any args" do
48+ allow ( guard ) . to receive ( :changed_files ) . and_return ( paths )
49+
50+ guard . run_all
51+ expect ( guard ) . to have_received ( :run_codespell ) . with ( paths )
52+ end
53+ end
4254 end
4355
4456 describe "#run_on_additions" do
You can’t perform that action at this time.
0 commit comments