summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/rev_list_spec.rb
blob: 78894ba94090c0107e3cdd769d5c1daa9b241762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'

describe Gitlab::Git::RevList, lib: true do
  let(:project) { create(:project, :repository) }

  before do
    expect(Gitlab::Git::Env).to receive(:all).and_return({
      GIT_OBJECT_DIRECTORY: 'foo',
      GIT_ALTERNATE_OBJECT_DIRECTORIES: 'bar'
    })
  end

  context "#new_refs" do
    let(:rev_list) { Gitlab::Git::RevList.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }

    it 'calls out to `popen`' do
      expect(Gitlab::Popen).to receive(:popen).with([
        Gitlab.config.git.bin_path,
        "--git-dir=#{project.repository.path_to_repo}",
        'rev-list',
        'newrev',
        '--not',
        '--all'
      ],
      nil,
      {
        'GIT_OBJECT_DIRECTORY' => 'foo',
        'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar'
      }).and_return(["sha1\nsha2", 0])

      expect(rev_list.new_refs).to eq(%w[sha1 sha2])
    end
  end

  context "#missed_ref" do
    let(:rev_list) { Gitlab::Git::RevList.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }

    it 'calls out to `popen`' do
      expect(Gitlab::Popen).to receive(:popen).with([
        Gitlab.config.git.bin_path,
        "--git-dir=#{project.repository.path_to_repo}",
        'rev-list',
        '--max-count=1',
        'oldrev',
        '^newrev'
      ],
      nil,
      {
        'GIT_OBJECT_DIRECTORY' => 'foo',
        'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar'
      }).and_return(["sha1\nsha2", 0])

      expect(rev_list.missed_ref).to eq(%w[sha1 sha2])
    end
  end
end