piotrmurach / tty

Toolkit for developing sleek command line apps.
https://ttytoolkit.org
MIT License
2.5k stars 78 forks source link

teletype new causes 'fatal: not a git repository (or any of the parent directories): .git' which is not really fatal #48

Closed jayjlawrence closed 5 years ago

jayjlawrence commented 5 years ago

Describe the problem

Running teletype new project will cause the following error to be emitted under ruby 2.5.1 on MacOS:

fatal: not a git repository (or any of the parent directories): .git

Steps to reproduce the problem

$ teletype new fubar

Cause

There is a call to Gem::Specification.load. This load invokes 'git ls-files' to expand the 'spec.files' value. Despite having a Dir.chdir in the generated spec code it is still in the wrong directory when this runs.

This is the code generated

  # Specify which files should be added to the gem when it is released.
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
  spec.files         = Dir.chdir(File.expand_path('..', __FILE__)) do
    `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
  end

Putting a Dir.chdir in the calling code mitigates this issue.

Fix

( I couldn't get the gem package built properly so I will not put in a PR. Instead offer the following edit)

In lib\tty\commands\new.rb

      def add_required_libs_to_gemspec
        Dir.chdir target_path do
   ....
       end
     end

Describe your environment

piotrmurach commented 5 years ago

Thanks for reporting! This is already fixed in the master branch.