Skip to content

Commit

Permalink
init does not overide exist README.md.
Browse files Browse the repository at this point in the history
When invoking `dotgpg init`, check if a README.md already exist.
If so, do not create a README.md.
This avoids overide exist README.md in the directory.
  • Loading branch information
weakish committed Dec 1, 2014
1 parent dbee517 commit df74b88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/dotgpg/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def init(directory=".")
key = Dotgpg::Key.secret_key(options[:email], options[:"new-key"])

info "Initializing new dotgpg directory"
info " #{directory}/README.md"
info " #{directory}/README.md" unless File.exist? 'README.md'
info " #{directory}/.gpg/#{key.email}"

FileUtils.mkdir_p(dir.dotgpg)
FileUtils.cp Pathname.new(__FILE__).dirname.join("template/README.md"), dir.path.join("README.md")
unless File.exist? 'README.md'
FileUtils.cp Pathname.new(__FILE__).dirname.join("template/README.md"), dir.path.join("README.md")
dir.add_key(key)
end
end

desc "key", "export your GPG public key in a format that `dotgpg add` will understand"
Expand Down
5 changes: 5 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
assert_equal $fixture.join("create-3", ".gpg", "[email protected]").read, GPGME::Key.find(:secret).first.export(armor: true).to_s
end

it "should not add a README if there is already one" do |variable|
FileUtils.touch 'README.md'
assert_not_equal File.read('README.md'), File.read($basic + 'README.md')
end

it "should fail if the .gpg directory already exists" do
FileUtils.mkdir_p $fixture + "create-4" + ".gpg"
assert_fails(/\.gpg already exists/) do
Expand Down

0 comments on commit df74b88

Please sign in to comment.