Sha256: eae1968e4e1f604a958aac29184c52b8fc4323080c6a59686a4ac7b361c6bda3

Contents?: true

Size: 920 Bytes

Versions: 49

Compression:

Stored size: 920 Bytes

Contents

module Grit

  class Merge

    STATUS_BOTH = 'both'
    STATUS_OURS = 'ours'
    STATUS_THEIRS = 'theirs'

    attr_reader :conflicts, :text, :sections

    def initialize(str)
      status = STATUS_BOTH

      section = 1
      @conflicts = 0
      @text = {}

      lines = str.split("\n")
      lines.each do |line|
        if /^<<<<<<< (.*?)/.match(line)
          status = STATUS_OURS
          @conflicts += 1
          section += 1
        elsif line == '======='
          status = STATUS_THEIRS
        elsif /^>>>>>>> (.*?)/.match(line)
          status = STATUS_BOTH
          section += 1
        else
          @text[section] ||= {}
          @text[section][status] ||= []
          @text[section][status] << line
        end
      end
      @text = @text.values
      @sections = @text.size
    end

    # Pretty object inspection
    def inspect
      %Q{#<Grit::Merge}
    end
  end # Merge

end # Grit

Version data entries

49 entries across 49 versions & 10 rubygems

Version Path
gitlab-grit-2.8.3 lib/grit/merge.rb
gitlab-grit-2.8.2 lib/grit/merge.rb
gitlab-grit-2.8.1 lib/grit/merge.rb
gitlab-grit-2.8.0 lib/grit/merge.rb
gitlab-grit-2.7.3 lib/grit/merge.rb
gitlab-grit-2.6.12 lib/grit/merge.rb
gitlab-grit-2.7.2 lib/grit/merge.rb
gitlab-grit-2.6.11 lib/grit/merge.rb
gitlab-grit-2.7.1 lib/grit/merge.rb
gitlab-grit-2.6.10 lib/grit/merge.rb
gitlab-grit-2.7.0 lib/grit/merge.rb
gitlab-grit-2.6.9 lib/grit/merge.rb
gitlab-grit-2.6.8 lib/grit/merge.rb
gitlab-grit-2.6.7 lib/grit/merge.rb
gitlab-grit-2.6.6 lib/grit/merge.rb
gitlab-grit-2.6.5 lib/grit/merge.rb
gitlab-grit-2.6.4 lib/grit/merge.rb
gitlab-grit-2.6.3 lib/grit/merge.rb
gitlab-grit-2.6.2 lib/grit/merge.rb
gitlab-grit-2.5.2 lib/grit/merge.rb