Repository navigation
Conversation
`overcommit --run` checks every file `git ls-files` lists, which includes tracked files that were deleted but whose deletion is not staged. Hooks then fail trying to read them (e.g. JsonSyntax raises 'No such file or directory'). Skip the files `git ls-files --deleted` reports.
Contributor
Author
|
The four failing |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #699: this fixes the
overcommit --runcase narrowed down in #699 (comment) and #699 (comment). The renamed-file behaviour in the original report (during a normal commit) is not changed here.GitRepo.all_filesreturns everythinggit ls-fileslists. That includes a tracked file that has been deleted from the working tree when the deletion is not staged yet.overcommit --runusesall_filesas its list of modified files, so every hook that reads itsapplicable_filesthen fails on that path. WithJsonSyntaxenabled:all_filesnow drops the pathsgit ls-files --deletedreports. This uses Git's own view rather thanFile.exist?, so a tracked broken symlink is still listed (theBrokenSymlinkshook needs it).included_files(used by the pre-pushMinitesthook) goes throughall_filestoo, so it no longer passes a deleted file either.Tests
A new context in
spec/overcommit/git_repo_spec.rbdeletes a committed file without staging the deletion and checks thatall_filesno longer includes it but still includes the other files.Run on macOS with Ruby 4.0.7 and Git 2.54.0:
bundle exec rspec spec/overcommit/git_repo_spec.rb -e '.all_files':4 examples, 1 failurewithlib/overcommit/git_repo.rbfrom main (the new "is expected not to include .../tracked" example),4 examples, 0 failureswith the change.JsonSyntaxenabled, a committeda.jsondeleted from the working tree, thenovercommit --run: main fails withNo such file or directory @ rb_sysopen; with the change,[JsonSyntax] OK.bundle exec rspec:1659 examples, 4 failures. The same 4 examples fail on main: the git alias#amendment?examples inhook_context/commit_msg_spec.rb:134,140andhook_context/pre_commit_spec.rb:43,49, which look specific to this machine's Git (Apple Git).bundle exec rubocop: no offenses.Not run: anything on Windows or Linux.