Skip to content

Doesn't Handle Submodules #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rpocklington opened this issue Oct 28, 2019 · 7 comments
Closed

Doesn't Handle Submodules #424

rpocklington opened this issue Oct 28, 2019 · 7 comments

Comments

@rpocklington
Copy link

Subject of the issue

The project doesn't appear to handle repositories loaded as submodules.

Your environment

  • git version 2.17.2 (Apple Git-113)
  • Gem: git (1.5.0)
  • ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]

Steps to reproduce

  1. Create a repository foo
  2. Create another repository bar
  3. Add bar as a submodule to foo
  4. Call g = Git.open("foo/bar")
  5. Call g.config

Expected behaviour

g.config returns a hash of configuration properties for the bar repository.

Actual behaviour

Errno::ENOTDIR (Not a directory @ dir_chdir - /Users/someuser/projects/foo/bar/.git)

Full output:

[someuser: ~/projects/foo (master)]$ irb
2.5.1 :001 > require 'git'
 => true
2.5.1 :002 > g = Git.open("bar")
 => #<Git::Base:0x00007fdf64880fe0 @logger=nil, @working_directory=#<Git::WorkingDirectory:0x00007fdf64880cc0 @path="/Users/someuser/projects/foo/bar">, @repository=#<Git::Repository:0x00007fdf64880b30 @path="/Users/someuser/projects/foo/bar/.git">, @index=#<Git::Index:0x00007fdf64880950 @path="/Users/someuser/projects/foo/bar/.git/index">>
2.5.1 :003 > g.config
Traceback (most recent call last):
        5: from /Users/someuser/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
        4: from (irb):3
        3: from /Users/someuser/.rvm/gems/ruby-2.5.1/gems/git-1.5.0/lib/git/base.rb:123:in `config'
        2: from /Users/someuser/.rvm/gems/ruby-2.5.1/gems/git-1.5.0/lib/git/lib.rb:465:in `config_list'
        1: from /Users/someuser/.rvm/gems/ruby-2.5.1/gems/git-1.5.0/lib/git/lib.rb:465:in `chdir'
Errno::ENOTDIR (Not a directory @ dir_chdir - /Users/someuser/projects/foo/bar/.git)
2.5.1 :004 > exit

[someuser: ~/projects/foo (master)]$ cat bar/.git
gitdir: ../.git/modules/dashboards
@rpocklington
Copy link
Author

Note from git documentation:

Also you can have a plain text file .git at the root of your working tree, containing gitdir: to point at the real directory that has the repository. This mechanism is often used for a working tree of a submodule checkout, to allow you in the containing superproject to git checkout a branch that does not have the submodule.

@rpocklington
Copy link
Author

rpocklington commented Oct 28, 2019

As a workaround, it appears to work if I set the :repository option manually:

g = Git.open("bar", :repository => ".git/modules/bar")

For a full fix, I think lib/git/base.rb:48 needs to be updated to check what kind of .git file/folder exists in the working directory:

      opts[:repository] ||= File.join(opts[:working_directory], '.git')

@rpocklington
Copy link
Author

Now I see there's already code to handle this in base.rb... I'll investigate why it isn't working for me.

@rpocklington
Copy link
Author

Ah. The Git::open method never hits that codepath.

The check needs to be added to Base's constructor.

@stale
Copy link

stale bot commented Dec 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 27, 2019
@stale stale bot closed this as completed Jan 3, 2020
@Kagetsuki
Copy link

This needs to be re-opened.

@jcouball
Copy link
Member

This was fixed in #499

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants