Permalink
Browse files

Don't abort execution if git repository is not yet ready

  • Loading branch information...
1 parent 833420e commit 29b497a71c507748542d211cf2b92e86bac8a273 @ayanko ayanko committed Nov 3, 2011
Showing with 12 additions and 5 deletions.
  1. +1 −1 capistrano-uptodate.gemspec
  2. +11 −4 lib/capistrano/uptodate.rb
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "capistrano-uptodate"
- s.version = "0.0.1"
+ s.version = "0.0.2"
s.authors = ["Andriy Yanko"]
s.email = ["andriy.yanko@gmail.com"]
s.homepage = "https://github.com/railsware/capistrano-uptodate"
View
@@ -19,19 +19,26 @@
end
task :git do
+ # skip if no git dir detected
git_dir = fetch(:uptodate_local_reposytory, `#{scm_binary} rev-parse --git-dir`.strip)
- abort "Can't detect git repository" if git_dir.empty?
+ next if git_dir.empty?
- fetch_file = File.join(git_dir, "FETCH_HEAD")
+ # skip if remote is not yet configured
+ remote_reference_file = File.join(git_dir, 'refs', 'remotes', remote_repository, branch)
+ next unless File.exists?(remote_reference_file)
+ # fetch remote references and skip on error
+ fetch_file = File.join(git_dir, "FETCH_HEAD")
unless File.exist?(fetch_file) && Time.now - File.mtime(fetch_file) < time
- Capistrano::CLI.ui.say "Fetching references from #{repository} repository ..."
- system("#{scm_binary} fetch #{remote_repository}")
+ Capistrano::CLI.ui.say "Fetching references from #{remote_repository} repository ..."
+ next unless system("#{scm_binary} fetch #{remote_repository}")
end
+ # get commit for local and remote reference
local_commit = `#{scm_binary} rev-parse #{branch}`.strip
remote_commit = `#{scm_binary} rev-parse #{remote_repository}/#{branch}`.strip
+ # compare local and remote commit
if local_commit != remote_commit
Capistrano::CLI.ui.say "Local '#{branch}' branch is not synchronized with '#{remote_repository}' repository."

0 comments on commit 29b497a

Please sign in to comment.