Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Package untracked asset files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Oct 22, 2011
1 parent 5ef704b commit 867594d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/kumade/git.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/kumade/packager.rb
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/kumade/git_spec.rb
Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/support/git.rb
Expand Up @@ -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

0 comments on commit 867594d

Please sign in to comment.