lib/gitdocs/runner.rb in gitdocs-0.2.0 vs lib/gitdocs/runner.rb in gitdocs-0.3.0

- old
+ new

@@ -1,23 +1,26 @@ module Gitdocs class Runner attr_accessor :root - def initialize(root, opts = nil) - @root = root - out, status = sh_with_code "which growlnotify" - @use_growl = opts && opts.key?(:growl) ? opts[:growl] : status.success? - @polling_interval = opts && opts[:polling_interval] || 15 + def initialize(share) + @share = share + @root = share.path + @polling_interval = share.polling_interval @icon = File.expand_path("../../img/icon.png", __FILE__) end def run - info("Running gitdocs!", "Running gitdocs in `#{@root}'") - @current_remote = sh_string("git config branch.`git branch | grep '^\*' | sed -e 's/\* //'`.remote", 'origin') - @current_branch = sh_string("git branch | grep '^\*' | sed -e 's/\* //'", 'master') + return false unless self.valid? + out, status = sh_with_code "which growlnotify" + @use_growl = @share.notification && status.success? + @current_remote = @share.remote_name + @current_branch = @share.branch_name @current_revision = sh_string("git rev-parse HEAD") + info("Running gitdocs!", "Running gitdocs in `#{@root}'") + mutex = Mutex.new # Pull changes from remote repository Thread.new do loop do mutex.synchronize { sync_changes } @@ -55,11 +58,10 @@ h } warn("There were some conflicts", "#{conflicted_files.keys.map{|f| "* #{f}"}.join("\n")}") conflicted_files.each do |conflict, ids| conflict_start, conflict_end = conflict.scan(/(.*?)(|\.[^\.]+)$/).first - puts "solving #{conflict} with #{ids.inspect}" ids.each do |(mode, sha, id)| author = " original" if id == "1" system("cd #{@root} && git show :#{id}:#{conflict} > '#{conflict_start} (#{sha[0..6]}#{author})#{conflict_end}'") end system("cd #{@root} && git rm #{conflict}") or raise @@ -107,9 +109,14 @@ lines end else [] end + end + + def valid? + out, status = sh_with_code "git status" + status.success? end def warn(title, msg) if @use_growl Growl.notify_warning(msg, :title => title)