Sha256: da2c0b3e9a08c5683027ac57bd987c944b15395b6d12209cb60ea89d19e29479

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module Gitlab
  module Git
    class Compare
      attr_reader :head, :base, :straight

      def initialize(repository, base, head, straight = false)
        @repository = repository
        @straight = straight

        unless base && head
          @commits = []
          return
        end

        @base = Gitlab::Git::Commit.find(repository, base.try(:strip))
        @head = Gitlab::Git::Commit.find(repository, head.try(:strip))

        @commits = [] unless @base && @head
        @commits = [] if same
      end

      def same
        @base && @head && @base.id == @head.id
      end

      def commits
        return @commits if defined?(@commits)

        @commits = Gitlab::Git::Commit.between(@repository, @base.id, @head.id)
      end

      def diffs(options = {})
        unless @head && @base
          return Gitlab::Git::DiffCollection.new([])
        end

        paths = options.delete(:paths) || []
        options[:straight] = @straight
        Gitlab::Git::Diff.between(@repository, @head.id, @base.id, options, *paths)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gitlab_git-10.7.0 lib/gitlab_git/compare.rb
gitlab_git-10.6.8 lib/gitlab_git/compare.rb