Sha256: fa5dec64e8b40957ed0e6a3d25635bea4e2c97933412f0bc3094efd9fe4f143d

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

require 'fileutils'
require 'tmpdir'

module Braid
  module Commands
    class Push < Command
      def run(path, options = {})
        mirror        = config.get!(path)

        #mirror.fetch

        base_revision = git.rev_parse(mirror.remote)
        unless mirror.merged?(base_revision)
          msg 'Mirror is not up to date. Stopping.'
          return
        end

        diff = mirror.diff
        if diff.empty?
          msg 'No local changes found. Stopping.'
          return
        end

        clone_dir = Dir.tmpdir + "/braid_push.#{$$}"
        Dir.mkdir(clone_dir)
        source_dir = Dir.pwd
        remote_url = git.remote_url(mirror.remote)
        if remote_url == mirror.cached_url
          remote_url = mirror.url
        elsif File.directory?(remote_url)
          remote_url = File.expand_path(remote_url)
        end
        Dir.chdir(clone_dir) do
          msg 'Cloning mirror with local changes.'
          git.init
          git.fetch(source_dir)
          git.fetch(remote_url, "+refs/heads/#{mirror.branch}")
          git.checkout(base_revision)
          git.apply(diff)
          system('git commit -v')
          msg 'Pushing changes to remote.'
          git.push(remote_url, "HEAD:#{mirror.branch}")
        end
        FileUtils.rm_r(clone_dir)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
braid-1.0.9 lib/braid/commands/push.rb
braid-1.0.8 lib/braid/commands/push.rb
braid-1.0.7 lib/braid/commands/push.rb
braid-1.0.6 lib/braid/commands/push.rb
braid-1.0.5 lib/braid/commands/push.rb
braid-1.0.4 lib/braid/commands/push.rb
braid-1.0.3 lib/braid/commands/push.rb
braid-1.0.2 lib/braid/commands/push.rb
braid-1.0.1 lib/braid/commands/push.rb
braid-1.0.0 lib/braid/commands/push.rb