diff --git a/lib/kumade/git.rb b/lib/kumade/git.rb index c40303d..fbdf2f7 100644 --- a/lib/kumade/git.rb +++ b/lib/kumade/git.rb @@ -68,6 +68,12 @@ def ensure_clean_git end end + def has_untracked_files_in?(directory) + relative_dir = directory.sub(Dir.pwd + '/', '') + untracked_output = CommandLine.new("git status --porcelain --untracked-files").run + untracked_output.split("\n").grep(/^\?{2} #{relative_dir}/).size > 0 + end + private def has_branch?(branch) diff --git a/lib/kumade/packager.rb b/lib/kumade/packager.rb index d826ccc..db96529 100644 --- a/lib/kumade/packager.rb +++ b/lib/kumade/packager.rb @@ -25,7 +25,7 @@ def package begin @packager.package - if @git.dirty? + if @git.dirty? || @git.has_untracked_files_in?(@packager.assets_path) @git.add_and_commit_all_assets_in(@packager.assets_path) Kumade.configuration.outputter.success(success_message) end diff --git a/spec/kumade/git_spec.rb b/spec/kumade/git_spec.rb index 3ce69bf..8d78f7a 100644 --- a/spec/kumade/git_spec.rb +++ b/spec/kumade/git_spec.rb @@ -227,3 +227,27 @@ end end end + +describe Kumade::Git, "#has_untracked_files_in?", :with_mock_outputter do + let(:untracked_dir) { 'untracked' } + + context "in normal mode" do + before do + Kumade.configuration.pretending = false + create_untracked_file_in(untracked_dir) + end + + it "detects untracked files" do + subject.should have_untracked_files_in(untracked_dir) + end + + it "detects untracked files when given an absolute path" do + subject.should have_untracked_files_in(File.expand_path("./" + untracked_dir)) + end + + it "does not get confused by tracked files" do + `git add . && git commit -am Message` + subject.should_not have_untracked_files_in(untracked_dir) + end + end +end diff --git a/spec/support/git.rb b/spec/support/git.rb index 8c096c8..e44ba86 100644 --- a/spec/support/git.rb +++ b/spec/support/git.rb @@ -2,4 +2,9 @@ module GitHelpers def dirty_the_repo `echo dirty_it_up > .gitkeep` end + + def create_untracked_file_in(directory) + FileUtils.mkdir_p(directory) + FileUtils.touch(File.join(directory, 'i-am-untracked')) + end end