| |   |
| 1 | require 'fileutils' |
| 2 | |
| 1 | 3 | module GitRails |
| 2 | 4 | module Commands |
| 3 | 5 | class Init < GitRails::Command |
| 4 | | |
| 5 | 6 | def run(remote, message='', commit=false) |
| 6 | | unless File.exists?(".gitignore") |
| 7 | | gitignore = File.new(".gitignore", "w") |
| 8 | | gitignore << "log/*.log\n" |
| 9 | | gitignore << "tmp/**/*\n" |
| 10 | | gitignore << ".DS_Store\n" |
| 11 | | gitignore << "public/cache/**/*\n" |
| 12 | | gitignore << "doc/api\n" |
| 13 | | gitignore << "doc/app\n" |
| 14 | | gitignore.close |
| 15 | | end |
| 16 | | FileUtils.mkdir_p("log") |
| 17 | | gitignore = File.new("log/.gitignore", "w") |
| 18 | | gitignore.close |
| 19 | | FileUtils.mkdir_p("tmp") |
| 20 | | gitignore = File.new("tmp/.gitignore", "w") |
| 21 | | gitignore.close |
| 22 | | |
| 7 | ignore(".", ".DS_Store") |
| 8 | ignore("config", "database.yml") |
| 9 | ignore("db", ["*.db", "*.sqlite*"]) |
| 10 | ignore("log", "*.log") |
| 11 | ignore("tmp", "[^.]*") |
| 12 | ignore("public/cache", "[^.]*") |
| 13 | ignore("doc", ["api","app"]) |
| 14 | |
| 23 | 15 | git = GitRails::Git.new |
| 24 | 16 | git.init |
| 25 | 17 | git.add(".") |
| … | … | |
| 29 | 29 | puts " git push origin master\n" |
| 30 | 30 | end |
| 31 | 31 | end |
| 32 | | |
| 32 | private |
| 33 | def ignore(path, entries) |
| 34 | file = path + "/.gitignore" |
| 35 | unless File.exists?(file) |
| 36 | FileUtils.mkdir_p(path) |
| 37 | handle = File.new(file, "w") |
| 38 | entries.each do |entry| |
| 39 | handle << "#{entry}\n" |
| 40 | end |
| 41 | handle.close |
| 42 | end |
| 43 | end |
| 33 | 44 | end |
| 34 | 45 | end |
| 35 | 46 | end |
| toggle raw diff |
--- a/lib/git-rails/commands/init.rb
+++ b/lib/git-rails/commands/init.rb
@@ -1,25 +1,17 @@
+require 'fileutils'
+
module GitRails
module Commands
class Init < GitRails::Command
-
def run(remote, message='', commit=false)
- unless File.exists?(".gitignore")
- gitignore = File.new(".gitignore", "w")
- gitignore << "log/*.log\n"
- gitignore << "tmp/**/*\n"
- gitignore << ".DS_Store\n"
- gitignore << "public/cache/**/*\n"
- gitignore << "doc/api\n"
- gitignore << "doc/app\n"
- gitignore.close
- end
- FileUtils.mkdir_p("log")
- gitignore = File.new("log/.gitignore", "w")
- gitignore.close
- FileUtils.mkdir_p("tmp")
- gitignore = File.new("tmp/.gitignore", "w")
- gitignore.close
-
+ ignore(".", ".DS_Store")
+ ignore("config", "database.yml")
+ ignore("db", ["*.db", "*.sqlite*"])
+ ignore("log", "*.log")
+ ignore("tmp", "[^.]*")
+ ignore("public/cache", "[^.]*")
+ ignore("doc", ["api","app"])
+
git = GitRails::Git.new
git.init
git.add(".")
@@ -37,7 +29,18 @@ module GitRails
puts " git push origin master\n"
end
end
-
+ private
+ def ignore(path, entries)
+ file = path + "/.gitignore"
+ unless File.exists?(file)
+ FileUtils.mkdir_p(path)
+ handle = File.new(file, "w")
+ entries.each do |entry|
+ handle << "#{entry}\n"
+ end
+ handle.close
+ end
+ end
end
end
end |