Sha256: bffb4944b66d5aa6745326e17f6360e9cc5b36e7acd98461a6a23feafe1ec707

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

require 'grit'

module Blazing
  class Repository

    include Blazing::Logger

    def initialize(target)
      @target = target
      @shell = Blazing::Shell.new
    end

    def setup
      # TODO: Handle case where user is empty
      if @target.host
        @shell.run "ssh #{@target.user}@#{@target.host} '#{init_repository} && #{setup_repository}'"
      else
        @shell.run "#{init_repository} && #{setup_repository}"
      end
    end

    def add_git_remote
      info "Adding new remote #{@target.name} pointing to #{@target.location}"
      set_git_remote!
    end

    private

    #
    # Initialize an empty repository
    #
    def init_repository
      # Instead of git init with a path, so it does not fail on older
      # git versions (https://github.com/effkay/blazing/issues/53)
      "mkdir #{@target.path}; cd #{@target.path} && git init"
    end

    #
    # Allow pushing to currently checked out branch
    #
    def setup_repository
      "cd #{@target.path} && git config receive.denyCurrentBranch ignore"
    end

    def grit_repository_object
      @grit_object ||= Grit::Repo.new(Dir.pwd)
    end

    def set_git_remote!
      grit_repository_object.config["remote.#{@target.name}.url"] = @target.location
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
blazing-0.4.2 lib/blazing/repository.rb
blazing-0.4.1 lib/blazing/repository.rb
blazing-0.4.0 lib/blazing/repository.rb
blazing-0.4.0.beta3 lib/blazing/repository.rb
blazing-0.4.0.beta2 lib/blazing/repository.rb
blazing-0.4.0.beta1 lib/blazing/repository.rb
blazing-0.3.0 lib/blazing/repository.rb
blazing-0.2.14 lib/blazing/repository.rb
blazing-0.2.13 lib/blazing/repository.rb
blazing-0.2.12 lib/blazing/repository.rb
blazing-0.2.11 lib/blazing/repository.rb