Class: Gitlab::Git::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_git/compare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, base, head) ⇒ Compare

Returns a new instance of Compare.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab_git/compare.rb', line 6

def initialize(repository, base, head)
  @commits = []
  @same = false
  @repository = repository

  return unless base && head

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

  return unless @base && @head

  if @base.id == @head.id
    @same = true
    return
  end

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

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def base
  @base
end

#commitsObject (readonly)

Returns the value of attribute commits.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def commits
  @commits
end

#headObject (readonly)

Returns the value of attribute head.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def head
  @head
end

#sameObject (readonly)

Returns the value of attribute same.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def same
  @same
end

Instance Method Details

#diffs(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/gitlab_git/compare.rb', line 26

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

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