rhyeal / aws-rotate-iam-keys

Rotate your IAM Keys to be in compliance with security best practices
GNU General Public License v3.0
339 stars 132 forks source link

fatal: --local can only be used inside a git repository #36

Closed pepastach closed 4 years ago

pepastach commented 4 years ago

I was having an issue with brew printing the following errors in almost any command. It took me hours to figure out it was related to aws-rotate-iam-keys...

It finally showed up when running in debug mode:

$ brew upgrade --verbose --debug
...
...
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::TapLoader): loading /usr/local/Homebrew/Library/Taps/rhyeal/homebrew-aws-rotate-iam-keys/Formula/aws-rotate-iam-keys.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/opt/aws-rotate-iam-keys/.brew/aws-rotate-iam-keys.rb
fatal: --local can only be used inside a git repository
fatal: --local can only be used inside a git repository
fatal: not a git repository (or any of the parent directories): .git
...
...

As you can see just loading the formula prints these errors.

Anyone else having the same issue?

rhyeal commented 4 years ago

I'll look into this issue. Is the fatal stopping you from running this command or is it just verbose output that's annoying?

mmrwoods commented 4 years ago

@pepastach Sorry, this is almost certainly due to some code I added :-(

This does seem strange though, my understanding is that Homebrew taps are added as cloned git repositories. Though there is code in the aws-rotate-iam-keys Homebrew formula that uses the git cli to determine the head and develop urls, by the time it runs, the current working directory should be in a git repo.

Could you check if you have .git directory within /usr/local/Homebrew/Library/Taps/rhyeal/homebrew-aws-rotate-iam-keys?

Assuming you do, what happens if you cd /usr/local/Homebrew/Library/Taps/rhyeal/homebrew-aws-rotate-iam-keys && git config --local --get remote.origin.url ?

If the above works, it seems there is a bug in my code :-( Could you help me debug it remotely?

Could you brew edit aws-rotate-iam-keys and add a new line after line 16 to print out the current working directory, e.g. update this block of code...

  head do
    Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git
    end
  end

to look like this instead...

  head do
    Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do
      puts 'Current working directory: ' + Dir.pwd
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git
    end
  end

The save the file and return to the terminal. Now run brew info aws-rotate-iam-keys and you should see the current working directory printed at the top of the output, e.g.

$ brew info aws-rotate-iam-keys
Current working directory: /usr/local/Homebrew/Library/Taps/rhyeal/homebrew-aws-rotate-iam-keys
...

What do you see? Is it /usr/local/Homebrew/Library/Taps/rhyeal/homebrew-aws-rotate-iam-keys or something slightly different?

mmrwoods commented 4 years ago

@pepastach another thing to try...

If you brew edit aws-rotate-iam-keys, replace File.dirname(__FILE__) with __dir__, save file and then brew info aws-rotate-iam-keys does that fix it?

i.e. replace these lines...

  head do
    Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do
      puts 'Current working directory: ' + Dir.pwd
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git
    end
  end

  devel do
    Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git, branch: "develop"
      version "head"
    end
  end

with these

  head do
    Dir.chdir(File.expand_path(File.join(__dir__, '../'))) do
      puts 'Current working directory: ' + Dir.pwd
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git
    end
  end

  devel do
    Dir.chdir(File.expand_path(File.join(__dir__, '../'))) do
      url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git, branch: "develop"
      version "head"
    end
  end

Thanks

Mark

mmrwoods commented 4 years ago

@pepastach This should, finally, be fixed in version 0.9.8.1, could you run brew update and then brew info aws-rotate-iam-keys and let us know if you still have this problem, thanks.

Note: there is a new Homebrew deprecation warning re devel blocks, ignore this, it's annoying but harmless. It will be addressed separately, soon.

pepastach commented 4 years ago

@mmrwoods I can confirm it's fixed now. Thank you!