Skip to content

Commit

Permalink
add relevant files to .gitignore if exists at setup; with specs
Browse files Browse the repository at this point in the history
  • Loading branch information
webcracy committed Oct 30, 2013
1 parent a71be80 commit 4bd3322
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/motion/project/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def certificates_ok?(silence=false)

def setup
create_sparkle_folder
add_to_gitignore
copy_templates
if config_ok?
App.info "Sparkle", "Config found"
Expand Down
22 changes: 21 additions & 1 deletion lib/motion/project/sparkle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ def public_key(path_in_resources_folder)

# File manipulation and certificates

def add_to_gitignore
@ignorable = ['sparkle/release','sparkle/release/*','sparkle/config/dsa_priv.pem']
return unless File.exist?(gitignore_path)
File.open(gitignore_path, 'r') do |f|
f.each_line do |line|
@ignorable.delete(line) if @ignorable.include?(line)
end
end
File.open(gitignore_path, 'a') do |f|
@ignorable.each do |i|
f << "#{i}\n"
end
end if @ignorable.any?
`cat #{gitignore_path}`
end

def create_sparkle_folder
create_config_folder
create_release_folder
Expand Down Expand Up @@ -100,7 +116,7 @@ def generate_keys
* Private certificate: ./#{private_key_path}
* Public certificate: ./#{public_key_path}
Warning:
ADD YOUR PRIVATE CERTIFICATE TO YOUR GITIGNORE OR EQUIVALENT AND BACK IT UP!
ADD YOUR PRIVATE CERTIFICATE TO YOUR `.gitignore` OR EQUIVALENT AND BACK IT UP!
KEEP IT PRIVATE AND SAFE!
If you lose it, your users will be unable to upgrade.
"
Expand All @@ -120,6 +136,10 @@ def project_path
@project_path ||= Pathname.new(@config.project_dir)
end

def gitignore_path
project_path + ".gitignore"
end

def sparkle_release_path
project_path + RELEASE_PATH
end
Expand Down
7 changes: 7 additions & 0 deletions spec/sparkle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Config
unless @completed_setup
teardown_temporary_directory
setup_temporary_directory

FileUtils.mkdir_p(temporary_directory + 'resources')
FileUtils.touch(temporary_directory + '.gitignore')

@config = App.config
@config.project_dir = temporary_directory.to_s
Expand Down Expand Up @@ -71,4 +73,9 @@ class Config
File.exist?(@config.sparkle.public_key_path.to_s).should.equal true
end

it "should add files to gitignore" do
a = `cat .gitignore`
a.strip.should.not.equal ''
end

end

0 comments on commit 4bd3322

Please sign in to comment.