Sha256: 4f6d1e7e0af296b4da4f3c45371cbf580dfd26ef6deaf78e5f244f5cd5c371ee

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

GIT_PROTO = { ssh:'git@', https: 'https://' }

def add_pre(url)
  res = url.split('/')	
  res[0] = "#{res[0]}:"
  res.join('/')
end

def add_writable(g,proto)
  readonly = g.remotes.find{|r|r.name.eql?('origin')}.url
  writable = readonly.gsub(/git\:\/\//,GIT_PROTO[proto])
  writable = add_pre(writable) if proto.eql?(:ssh)
  remote_exists = g.remotes.map {|r| r.name}.include?('writable')
  unless readonly.eql?(writable) or remote_exists
    g.add_remote('writable',writable) 
  end
end

module  Opsk
  class Push < Thor::Group
    include Thorable, Thor::Actions

    class_option :protocol, :type=> :string, :desc => 'remote ssh protocol (https or ssh)', :default => 'ssh'
    class_option :dry, :type=> :boolean, :desc => 'dry mode', :default => false
    class_option :all, :type=> :boolean, :desc => 'push all without asking', :default => false

    def validate
	check_root
    end


    def push
	Dir["modules/*"].reject{|o| not File.directory?(o)}.each do |d|
	  if File.exists?("#{d}/.git")
	    g = Git.init(d)
	    add_writable(g,options['protocol'].to_sym)
	    if !options['dry'] and g.diff('origin').stats[:files].keys.length > 0
		puts "push #{d}? (y/n)" unless options['all']
		if(options['all'] or STDIN.gets.chomp.eql?('y'))
		  puts "Pushing #{d} .."
		  g.push('writable') 
		  g.pull
		end
	    end
	  end
	end
    end


  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opskeleton-0.9.0 lib/opskeleton/push.rb