I am experiencing an issue with pre-commit hooks in overcommit, which is configured to run rubocop and rails_best_practices.
In short, all three commands listed below passed but overcommit wouldn't let me commit to git. Any advice on why/how to circumvent this issue would be appreciated.
# These passed
rubocop -a
rails_best_practices .
overcommit --run
# Git commit failed
$ overcommit --run
Running pre-commit hooks
Analyze with RailsBestPractices..................[RailsBestPractices] OK
Analyze with RuboCop........................................[RuboCop] OK
✓ All pre-commit hooks passed
$ git commit -m 'Ensure lower case with Attr API'
Running pre-commit hooks
Analyze with RailsBestPractices..................[RailsBestPractices] FAILED
Errors on modified lines:
/Users/USER_NAME/projects/APP_NAME/app/models/lower_case_string.rb:2 - remove unused methods (LowerCaseString#cast)
Analyze with RuboCop........................................[RuboCop] FAILED
Errors on modified lines:
/Users/USER_NAME/projects/APP_NAME/app/models/lower_case_string.rb:3:3: C: Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
✗ One or more pre-commit hooks failed
Now, I read here that overcommit --run doesn't trigger the hooks in the same ways that it does when you actually try to commit (whole project vs only changes to be committed). However, I'm not sure how this would affect my case, especially since rubocop and rails_best_practices both passed individually as well. By the way, the errors raised here are both false alarms. rails_best_practices shouldn't be checking for unused methods in the first place, since that check has been turned off in config/rails_best_practices.yml.
After a few weeks of working with these gems, I think I've figured it out. I'll leave some pointers here for anyone who encounters similar issues.
1. Stage your changes before doing overcommit --run with git add
<file>
As this comment and docs say, the --run command does not check untracked files.
2. Add gemfile option to .overcommit.yml
One issue I had was that overcommit was failing to read my config/rails_best_practices.yml (it wasn't supposed to be checking for unused methods in the first place, since that check was turned off in the config file).
It seems that when I was trying to git commit, overcommit was using gems installed in my system (not in the Gemfile), and as a result somehow failing to read my config file. So I added the gemfile option as recommended in the docs, and made sure overcommit uses the Gemfile/bundler version. I haven't gotten the subject error ever since. As the docs say:
If you are using Bundler to manage your Ruby gem dependencies, you'll likely want to use the gemfile option to control which gem versions are available during your hook runs.
My .overcommit.yml file for reference:
gemfile: Gemfile
PreCommit:
RuboCop:
enabled: true
on_warn: fail
RailsBestPractices:
enabled: true
on_warn: fail
command: ['bundle', 'exec', 'rails_best_practices', '-c', 'config/rails_best_practices.yml']
As a side note - I haven't tried this, but apparently you can also create a separate Gemfile just for overcommit purposes, if you feel that loading your original Gemfile slows down the hook execution (docs).
Related
For reasons pertaining to storage and git, installing homebrew comes with the issue of:
Error:
homebrew-core is a shallow clone.
homebrew-cask is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
It explicitly states what to do next, but I've found that running those git commands is a pretty terrible experience with slow internet (or just in general). The absolute best solution to such an issue would be if there were torrents which contained the entire project folder including git. Barring that, a simple download would be nice. Really, anything but git is in scope of this question.
To reiterate the issues with using git:
requires git
opaque UX by default (tends to hang without any updates for long periods of time)
not great for slow connections
wrong tool for a situation that only involves downloading files
Is there an alternative path to Homebrew that doesn't incorporate git?
As said in the comments, you can use the skip tap cloning feature of Homebrew. Note that this is, for now, a beta feature:
Skip Tap Cloning (beta)
You can instruct Homebrew to skip cloning the
Homebrew/homebrew-core tap during installation by setting the beta
HOMEBREW_INSTALL_FROM_API environment variable with the following:
export HOMEBREW_INSTALL_FROM_API=1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
This will make Homebrew install formulae and casks from the
homebrew/core and homebrew/cask taps using Homebrew’s API instead of
local checkouts of these repositories.
I agree with OP 100%.
Homebrew should simply provide a downloadable file. Especially since GitHub has implemented a very unfriendly interface and the default shell in MacOS Ventura is now zsh which Homebrew specifically states will not work with their provided Terminal install command.
If you make it so difficult to install your software, then don't be surprised that fewer people use it.
Edit: I suppose they just don't really care, but I spent a few hours trying to get Homebrew up to date tonight because of GitHub.
I have a Rails 6 project and am trying to use RuboCop's auto-correct option to fix the many Style/FrozenStringLiteralComment errors (mostly in generated files).
No matter how many times I run bundle exec rubocop --auto-correct --only Style/FrozenStringLiteralComment from the project root, Rubocop will only report the errors, but not auto-correct them:
app/models/product.rb:1:1: C: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
From running with the --show-cops option I can see that this cop 'Supports --auto-correct,' so am not sure what's wrong.
My .rubocop.yml file has only one config setting: require: rubocop-rails.
I've also run bundle exec rubocop -a and it has corrected other errors in config and similar files (single-quoting, mostly).
Any idea why auto-correct won't work in this case? Thanks.
This is a breaking change introduced in the version 0.87 (see the issue).
Quoting from there:
rubocop -a does all autocorrections, including unsafe ones. One has to add --safe-auto-correct to exclude unsafe ones.
You should use the -A flag now to safe and/or unsafe autocorrect your files:
rubocop -a / --autocorrect no longer run unsafe corrections; rubocop -A / --autocorrect-all run both safe and unsafe corrections. Options --safe-autocorrect is deprecated
It should work for you as:
bundle exec rubocop -A --only Style/FrozenStringLiteralComment
When forking a heroku app, I get the message "Cisaurus copy service no longer available. Use Heroku Platform API instead." No gem by that title is installed. What is causing this? Full output below, using [myapp] in place of the sourceapp name, and [targetapp] in place of the forked copy name:
[myapp]$ heroku fork -a [myapp] [targetapp]
Creating fork [targetapp]... done
Copying slug... Failed to fork app [myapp] to [targetapp].
! WARNING: Potentially Destructive Action
! This command will destroy edmeasured-sandbox (including all add-ons).
! To proceed, type "[targetapp]" or re-run this command with --confirm
[targetapp]
> [targetapp]
Deleting [targetapp]... done
Original exception below:
! Cisaurus copy service no longer available. Use Heroku Platform API instead. See: https://devcenter.heroku.com/articles/platform-api-copying-slugs
[targetapp]$
The issue is being caused by using an old version of Heroku Toolbelt. Updating via https://toolbelt.heroku.com allows the command to run as intended.
I am trying to install this gem: https://github.com/mongodb/mongo-ruby-driver (on the master branch).
When I run bundle install I get:
Enter PEM pass phrase:
(to which I don't have a key as this is a public repo, so I press enter)
OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key: nested asn1 error
I tried downloading the zip and bundling from source and get the exact same problem.
Update My Local Environment Variables
rvm_bin_path=/Users/Clay/.rvm/bin
TERM_PROGRAM=Apple_Terminal
GEM_HOME=/Users/Clay/.rvm/gems/ruby-2.0.0-p451
TERM=xterm-256color
SHELL=/bin/bash
IRBRC=/Users/Clay/.rvm/rubies/ruby-2.0.0-p451/.irbrc
TMPDIR=/var/folders/yl/7nzdd2wx2tzbrwr4bm8t25qr0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-8mCJ2I/Render
TERM_PROGRAM_VERSION=326
OLDPWD=/Users/Clay/Developer
MY_RUBY_HOME=/Users/Clay/.rvm/rubies/ruby-2.0.0-p451
TERM_SESSION_ID=63791880-F18D-4CD5-932D-109041B81415
USER=Clay
_system_type=Darwin
rvm_path=/Users/Clay/.rvm
SSH_AUTH_SOCK=/tmp/launch-8O5pHu/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
rvm_prefix=/Users/Clay
__CHECKFIX1436934=1
PATH=/Users/Clay/.rvm/gems/ruby-2.0.0-p451/bin:/Users/Clay/.rvm/gems/ruby-2.0.0-p451#global/bin:/Users/Clay/.rvm/rubies/ruby-2.0.0-p451/bin:/Users/Clay/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Users/Clay/Developer/mongodb-osx-x86_64-2.4.6/bin:/usr/local/mysql/support-files/:/Applications/Sublime Text.app/Contents/SharedSupport/bin/:/Users/Clay/Developer/AWS-ElasticBeanstalk-CLI-2.6.3/eb/macosx/python2.7/
PWD=/Users/Clay/Developer/mongo-ruby-driver
LANG=en_US.UTF-8
_system_arch=x86_64
_system_version=10.9
rvm_version=1.24.7 (stable)
HOME=/Users/Clay
SHLVL=1
RAILS_ENV=development
LOGNAME=Clay
GEM_PATH=/Users/Clay/.rvm/gems/ruby-2.0.0-p451:/Users/Clay/.rvm/gems/ruby-2.0.0-p451#global
DISPLAY=/tmp/launch-Pm5rac/org.macosforge.xquartz:0
RUBY_VERSION=ruby-2.0.0-p451
SECURITYSESSIONID=186f1
_system_name=OSX
_=/usr/bin/env
I suggest you first get it working using the stable version and without using bundle. If that works, then try the master branch and bundle.
First, try this and tell us if it succeeds:
gem install mongo
(If it fails then please copy/paste the exact results as an edit to your question.)
Second, try building the current stable version in a fresh directory:
rm -rf mongo-ruby-driver
git clone https://github.com/mongodb/mongo-ruby-driver.git
cd mongo-ruby-driver
git checkout 1.11.1
gem build mongo.gemspec
(If it fails then please copy/paste the exact results as an edit to your question.)
What you expect to see is:
Warning: No private key present, creating unsigned gem.
Successfully built RubyGem
Name: mongo
Version: 1.11.1
File: mongo-1.11.1.gem
(If you see anything different then please copy/paste the exact results as an edit to your question.)
If you still getting the PEM error when you try to build 1.11.1, then try editing mongo.gemspec. Comment out these lines that may be causing the PEM prompt:
# s.signing_key = 'gem-private_key.pem'
# s.cert_chain = ['gem-public_cert.pem']
Then retry the build:
gem build mongo.gemspec
(If the build fails, then I suggest looking at your gem environment to see if it's all as you expect. Run gem env and copy/paste the results into your question. Also, search your various gem env directories for a file called gem-private_key.pem. This file may be causing your issue; temporarily rename it and try again.)
If the build succeeds, then install as usual:
gem install mongo-1.11.1
If that all works, then you're in good shape.
If you're positive that you want the master branch:
git checkout master
gem build mongo.gemspec
My Capistrano deployments are hanging on the second command in a composite command.
https://github.com/capistrano/capistrano/blob/5986983915163e6681f2546bf6fad599d58cd024/lib/capistrano/dsl.rb#L59
At the point that SSHKit tries to run the following command:
cd /home/lawfm/deployments/staging/repo && git rev-parse
I get a
bash: git: command not found error.
I believe the issue is documented here:
https://github.com/capistrano/capistrano/issues/675
My deploy was working in 3.0.1, but an upgrade to 3.1 introduced the error. At first, I read that pty was now on by default, so I set:
set :pty, false
Unfortunately, it seems neither .bash_profile nor .profile are being loaded, so any attempt to augment the PATH there have been fruitless.
I can't seem to figure out a way to set the path or even map the git command directly since it's the second command.
I can't figure out a way to fix the path not being applied to the second command, but I did place the PATH definition in my .bashrc file instead of .bash_profile and it now works.