summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/gitmodules_parser_spec.rb
diff options
context:
space:
mode:
authorDavid Turner <novalis@novalis.org>2017-04-17 20:13:08 -0400
committerDavid Turner <novalis@novalis.org>2017-06-16 14:37:13 -0400
commitb30c16aa3298221b1957fef61e69c47be74bb25e (patch)
treef2f4a36f0970cc9663e408e34d2b3546875a74fb /spec/lib/gitlab/git/gitmodules_parser_spec.rb
parent4b1c49171dcdac5ba78a81bad94776644d9dbed5 (diff)
downloadgitlab-ce-b30c16aa3298221b1957fef61e69c47be74bb25e.tar.gz
repository: index submodules by path
Submodules have a name in the configuration, but this name is simply the path at which the submodule was initially checked in (by default -- the name is totally arbitrary). If a submodule is moved, it retains its original name, but its path changes. Since we discover submodules inside trees, we have their path but not necessarily their name. Make the submodules() function return the submodule hash indexed by path rather than name, so that renamed submodules can be looked up. Signed-off-by: David Turner <novalis@novalis.org>
Diffstat (limited to 'spec/lib/gitlab/git/gitmodules_parser_spec.rb')
-rw-r--r--spec/lib/gitlab/git/gitmodules_parser_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/gitmodules_parser_spec.rb b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
new file mode 100644
index 00000000000..143aa2218c9
--- /dev/null
+++ b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe Gitlab::Git::GitmodulesParser do
+ it 'should parse a .gitmodules file correctly' do
+ parser = described_class.new(<<-'GITMODULES'.strip_heredoc)
+ [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
+
+ 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