Sha256: a4e5f03085f6d94ce2078c9e812c90721ebc9febc425fa0d808d7ed7f08ecce1

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Middleman
  module Deploy
    module Strategies
      module Git
        class ForcePush < Base
          def process
            Dir.chdir(self.build_dir) do
              add_remote_url
              checkout_branch
              commit_branch('-f')
            end
          end

          private

          def add_remote_url
            url = get_remote_url

            unless File.exist?('.git')
              `git init`
              `git remote add origin #{url}`
            else
              # check if the remote repo has changed
              unless url == `git config --get remote.origin.url`.chop
                `git remote rm origin`
                `git remote add origin #{url}`
              end
            end
          end

          def get_remote_url
            remote  = self.remote
            url     = remote

            # check if remote is not a git url
            unless remote =~ /\.git$/
              url = `git config --get remote.#{url}.url`.chop
            end

            # if the remote name doesn't exist in the main repo
            if url == ''
              puts "Can't deploy! Please add a remote with the name '#{remote}' to your repo."
              exit
            end

            url
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-deploy-0.3.0 lib/middleman-deploy/strategies/git/force_push.rb