summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/gitmodules_parser_spec.rb
blob: 0e386c7f3d102c14ac51c51ffd54c9a8a969ff96 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Git::GitmodulesParser do
  it 'parses a .gitmodules file correctly' do
    data = <<~GITMODULES
      [submodule "vendor/libgit2"]
         path = vendor/libgit2
      [submodule "vendor/libgit2"]
         url = https://github.com/nodegit/libgit2.git

      # a comment
      [submodule "moved"]
          path = new/path
          url = https://example.com/some/project
      [submodule "bogus"]
          url = https://example.com/another/project
    GITMODULES

    parser = described_class.new(data.gsub("\n", "\r\n"))
    modules = parser.parse

    expect(modules).to eq({
                            'vendor/libgit2' => { 'name' => 'vendor/libgit2',
                                                  'url' => 'https://github.com/nodegit/libgit2.git' },
                            'new/path' => { 'name' => 'moved',
                                            'url' => 'https://example.com/some/project' }
                          })
  end
end