Sha256: e563ce87c87d70c697a3588b00c91c853a81b93ea56164d280ed5db0aba2030c

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

class Stencil
  class Merge
    class <<self
      
      def project(path)
        template = Config.read[:projects][@name][:template]
        branches = Config.read[:projects][@name][:branches]
        if template
          template = Config.read[:templates][template.intern]
          if template && File.exists?(template[:path])
            origin = Cmd.run template[:path], "git remote show origin"
            origin = origin.match(/URL:\s+(\S+)/)[1]
            Msg.template_url origin
            Cmd.run path, "git remote rm template"
            Cmd.run path, "git remote add template #{origin}"
            branches = %w(master) if branches.empty?
            branches.each do |branch|
              Msg.merge_remote_branch branch
              Cmd.run path, "git pull template #{branch}"
            end
          else
            Msg.template_not_found template
            Msg.specify_template
          end
        else
          Msg.specify_template
        end
      end
      
      def template(path)
        Branches.grouped(path).each do |branches|
          branches.unshift('master')
          progressive(path, branches)
        end
        Cmd.run path, "git checkout master"
      end
      
      private
      
      def progressive(path, branches)
        merger = branches.shift
        mergee = branches.first
        if merger && mergee
          puts "Merging \"#{merger}\" into \"#{mergee}\""
          output = Cmd.run(path, "git checkout #{mergee} && git merge #{merger}")
          if output.downcase.include?('conflict')
            puts output
          else
            progressive(path, branches)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stencil-0.1.0 lib/stencil/merge.rb