Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git@github.com:railsmachine/railsmachine

* 'master' of git@github.com:railsmachine/railsmachine:
  Make git import more robust for existing repositories.
  • Loading branch information...
commit 3a523142d7c779bbeba9b0f94cc00163fa6838ad 2 parents ba93ebd + 84fdc48
pinguskahn pinguskahn authored
Showing with 32 additions and 20 deletions.
  1. +32 −20 lib/railsmachine/recipes/scm/git.rb
52 lib/railsmachine/recipes/scm/git.rb
View
@@ -1,8 +1,8 @@
require 'fileutils'
Capistrano::Configuration.instance(:must_exist).load do
-
+
namespace :localrepo do
-
+
desc "Setup directory structure and initialize git repository on remote server"
task :setup, :roles => :scm do
dir = "#{deploy_to}/repos/#{application}.git"
@@ -15,30 +15,42 @@
desc "Import code into remote git repository."
task :import do
puts "Initializing local git repository"
- system "git init"
+ system "git init" unless File.directory?(".git")
puts "Adding remote server pointing to #{repository}"
- system "git remote add origin #{repository}"
+ remotes = `git remote`.split("\n").map {|r| `git remote show #{r}`}
+ remote_name = if existing_remote = remotes.find {|r| r =~ /URL: #{Regexp.escape(repository)}/ }
+ existing_remote.match(/\* remote (.*)$/)[1]
+ elsif remotes.any? {|r| r =~ /\* remote origin$/ }
+ Capistrano::CLI.ui.ask("Remote 'origin' already exists. Please name the remote you want to create:")
+ else
+ 'origin'
+ end
+ unless existing_remote
+ system "git remote add #{remote_name} #{repository}"
+ end
puts "Adding .gitignore file"
- system "echo 'log/*'>> .gitignore"
- system "echo 'tmp/*'>> .gitignore"
- system "echo '.DS_Store'>> .gitignore"
- system "echo 'public/cache/**/*'>> .gitignore"
- system "git add .gitignore"
-
- puts "Committing application locally"
- system "git add *"
- system 'git commit -a -v -m "initial import of site"'
-
- puts "Pushing application to the remote server. The name of the branch is:"
- system "git remote"
- system "git push origin master"
-
+ ignores = File.exist?('.gitignore') ? File.read('.gitignore') : ''
+ system "echo 'log/*'>> .gitignore" unless ignores =~ %r{log/\*}
+ system "echo 'tmp/*'>> .gitignore" unless ignores =~ %r{tmp/\*}
+ system "echo '.DS_Store'>> .gitignore" unless ignores =~ %r{\.DS_Store}
+ system "echo 'public/cache/**/*'>> .gitignore" unless ignores =~ %r{public/cache/\*\*/\*}
+ system "git add .gitignore && git commit -v -m 'Add ignores.'" if `git status` =~ %r{\.gitignore}
+
+ unless `git status` =~ /working directory clean/
+ puts "Committing application locally"
+ system "git add *"
+ system 'git commit -a -v -m "Import for RailsMachine"'
+ end
+
+ puts "Pushing application to the remote server '#{remote_name}'."
+ system "git push #{remote_name} master"
+
puts "git setup complete"
puts "You can clone this repository with git clone #{repository} #{application}"
end
-
+
end
-
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.