Classify bare repos by structure, not directory name#263
Merged
Conversation
Drop the `lastPathComponent.hasSuffix(".git")` gate around the
HEAD/objects/refs trio check in `Repository.isGitRepository(at:)` so
bare repos whose directory name does not end in `.git` (e.g.
`myrepo-bare/`) classify correctly instead of falling through to a
folder. Matches git's own `is_git_directory()` heuristic. Also require
`HEAD` to be a regular file so a directory with three child dirs named
HEAD/objects/refs is not a false positive.
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.
Summary
Repository.isGitRepository(at:)dropped thelastPathComponent.hasSuffix(".git")gate around the HEAD/objects/refs trio check, so user-renamed bare repos (e.g.myrepo-bare/) classify correctly instead of falling through to a folder. Matches git's ownis_git_directory()heuristic. Follow-up to Add folder (non-git) repository support + harden removal pipeline #257 after user reports of bare repos being misclassified.HEADnow must be a regular file (not a directory) —fileExists(atPath:isDirectory:)with a guard against the directory case — so a plain dir with three child dirs named HEAD/objects/refs is not a false positive.repositoryClassificationLoggerdamaged-bare-clone warning. Its sole caller (the rejected.git-suffixed path) no longer exists as a distinct misclassification case.Test plan
make check(swift-format + swiftlint, strict)make test— 939 tests pass, 12 pre-existing known issues unchangedisGitRepositoryRecognizesBareRepositoryRegardlessOfName— HEAD+objects+refs at a non-*.gitpath → gitisGitRepositoryRejectsDirectoryMissingGitStructure— two of three trio members → folderisGitRepositoryRejectsHeadDirectoryLookalike— HEAD/objects/refs all as directories → folderisGitRepositoryReturnsFalseForNonexistentPath— vanished path → folder, no crash.bare/.git-pointer-file tests still pass unchanged