Skip to content

Commit 62285cc

Browse files
TJ Biddlerobertodecurnex
TJ Biddle
authored andcommitted
Support Submodules
When a submodule is cloned into another project, it has a different structure: The .git folder is well, not a folder, it is a file that's sole contents include a reference to where the .git folder for the submodule is on the local drive. Take that information from the .git *file* and then build our repository and index location out of this.
1 parent b62ed86 commit 62285cc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/git/base.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ def self.init(working_dir, opts = {})
5454
}
5555

5656
opts.delete(:working_directory) if opts[:bare]
57+
58+
# Submodules have a .git *file* not a .git folder.
59+
# This file's contents point to the location of
60+
# where the git refs are held (In the parent repo)
61+
if File.file?('.git')
62+
git_file = File.open('.git').read[8..-1].strip
63+
opts[:repository] = git_file
64+
opts[:index] = git_file + '/index'
65+
end
5766

5867
Git::Lib.new(opts).init(init_opts)
5968

0 commit comments

Comments
 (0)