Class: GitRails::Commands::Init

Inherits:
GitRails::Command show all
Defined in:
lib/git-rails/commands/init.rb

Instance Attribute Summary

Attributes inherited from GitRails::Command

#config, #git, #local, #svn

Instance Method Summary collapse

Methods inherited from GitRails::Command

#initialize, run

Constructor Details

This class inherits a constructor from GitRails::Command

Instance Method Details

#run(remote, message = '', commit = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/git-rails/commands/init.rb', line 5

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
  
  git = GitRails::Git.new
  git.init
  git.add(".")
  git.commit_all('', message ? {"-m" => "\"#{message}\""} : {}) if commit
  if (remote)
    config = File.new(".git/config", "a")
    config << "[remote \"origin\"]\n"
    config << "        url = #{remote}\n"
    config << "        fetch = +refs/heads/*:refs/remotes/origin/*\n"
    config << "[branch \"master\"]\n"
    config << "        remote = origin\n"
    config << "        merge = refs/heads/master\n"
    config.close
    puts "You can now push to the origin #{remote} by using:\n"
    puts "  git pust origin master\n"
  end
end