Repository: ruby-git/ruby-git (Ruby)

Issue:
Git::Object::Tree#check_tree throws exception on a submodule, type 'commit'
### Subject of the issue

If I execute the following code on a workspace with a submodule:

```ruby
git = Git.open(@workspace_path, log: @logger)
gtree = git.gtree('HEAD')
head_sha = gtree.sha
subtrees = gtree.subtrees
```

... it fails with an undefined-method access on `Nil`.  

### Your environment

* ruby-git: 1.7.0

```console
> ruby --version
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin18]
> git version
git version 2.21.1 (Apple Git-122.3)
  ```

### Steps to reproduce

1. clone a repo with a submodule reference
1. execute code in [subject](#subject-of-the-issue)

### Expected behaviour

`gtree.subtrees` should return a Hash of `String, Git::Object::Tree` entries.  (The existence of a submodule, ie a `commit` in `git ls-tree`, should not matter.)

### Actual behaviour

Git::Lib#ls_tree [has buckets for `blob`s and `tree`s][lib-rb-L275], but no buckets for other types, and no way to dodge around unknown types.  It finds a `commit` type object in the `git ls-tree` output, tries to [add the details of it to `data['commit'][filenm]`][lib-rb-L280], and breaks.

[lib-rb-L275]: https://github.com/ruby-git/ruby-git/blob/861eb71e1c266606eefacf7ebd4bee4f34bee5de/lib/git/lib.rb#L275
[lib-rb-L280]: https://github.com/ruby-git/ruby-git/blob/861eb71e1c266606eefacf7ebd4bee4f34bee5de/lib/git/lib.rb#L280

Log from the event:

```console
> bundle exec bin/do_my_thing -C .../project-with-submodule/directory-I-want
DEBUG: initializing for path .../project-with-submodule
INFO: Starting Git
INFO: git '--git-dir=.../project-with-submodule/.git' '--work-tree=.../project-with-submodule' '-c' 'color.ui=false' remote   2>&1
DEBUG: upstream
INFO: git '--git-dir=.../project-with-submodule/.git' '--work-tree=.../project-with-submodule' '-c' 'color.ui=false' config '--list'  2>&1
DEBUG: credential.helper=osxkeychain
user..... # redacted
color.ui=false
DEBUG: select origin from remotes: selecting the only remote found
INFO: git '--git-dir=.../project-with-submodule/.git' '--work-tree=.../project-with-submodule' '-c' 'color.ui=false' rev-parse 'HEAD'  2>&1
DEBUG: 5678e0c4bfc065bc4376d90d9c73610718d5bdac
INFO: git '--git-dir=.../project-with-submodule/.git' '--work-tree=.../project-with-submodule' '-c' 'color.ui=false' ls-tree 'HEAD'  2>&1
DEBUG: 100644 blob 866460808185230ccdd7550c52c26e416c4b9f3e	.gitignore
100644 blob 10afd8c81744c73ff197a6c929f674e31dc3afa4	.gitmodules
100644 blob e3e5603674013c56497287eac57307288ace6397	README.md
040000 tree 0399189c0abe35c236d28c7e5f9d4076fc083db2	another-directory
160000 commit b9ade9bfd3fbd436fb224e1340e8bf19196604c6	hated-submodule
040000 tree 1989bf2c80f7854e0257d5ab70f9b980c2fc9a1e	directory-I-want
100644 blob 408810cf89ad4a5c3008b707285f42284893a62e	that-file
100644 blob d8327e75a5cadb9fe42a7e1cb9b6d19e27320123	this-file
WARN: cannot access item 'deploy' from 'deploy' in git index; NoMethodError - undefined method `[]=' for nil:NilClass
ERROR: undefined method `[]=' for nil:NilClass
	.../my-project/vendor/bundle/ruby/2.6.0/gems/git-1.7.0/lib/git/lib.rb:280:in `block in ls_tree'
	.../my-project/vendor/bundle/ruby/2.6.0/gems/git-1.7.0/lib/git/lib.rb:277:in `each'
	.../my-project/vendor/bundle/ruby/2.6.0/gems/git-1.7.0/lib/git/lib.rb:277:in `ls_tree'
	.../my-project/vendor/bundle/ruby/2.6.0/gems/git-1.7.0/lib/git/object.rb:138:in `check_tree'
	.../my-project/vendor/bundle/ruby/2.6.0/gems/git-1.7.0/lib/git/object.rb:114:in `trees'
	bin/do_my_thing:68:in `block in config'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
	.../.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
	.../.rbenv/versions/2.6.6/bin/bundle:23:in `load'
	.../.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
```

### Suggested change




Discussion: A friendly reminder that this issue had no activity for 60 days.




Fix (patch):
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 74b31862..02c59363 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -338,7 +338,7 @@ def object_contents(sha, &block)
     end
 
     def ls_tree(sha)
-      data = {'blob' => {}, 'tree' => {}}
+      data = { 'blob' => {}, 'tree' => {}, 'commit' => {} }
 
       command_lines('ls-tree', sha).each do |line|
         (info, filenm) = line.split("\t")