Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start matching pathname directory prefixes more rigorously #1175

Merged
merged 2 commits into from
Sep 18, 2022

Conversation

paracycle
Copy link
Member

Fixes #1174

Motivation

The simplistic start_with? check was not sufficient to match that a given file/folder was under a given folder, since we were not explicitly checking for full folder name matches. For example, if path = "/foo/bar-gem/baz" and folder = "/foo/bar", then path.start_with?(folder) would return true, but path is not under the folder directory.

Implementation

This commit fixes the problem by matching folder to any of the parent directories of path by using the Pathname#ascend method to get all parent directory prefixes of a path.

Tests

Added a test that fails without the fix.

@paracycle paracycle requested a review from a team as a code owner September 16, 2022 22:13
@paracycle paracycle force-pushed the uk-fix-directory-comparison branch from e5fdc2a to 691e369 Compare September 16, 2022 22:14
Fixes #1174

The simplistic `start_with?` check was not sufficient to match that a
given file/folder was under a given folder, since we were not explicitly
checking for full folder name matches. For example, if
`path = "/foo/bar-gem/baz"` and `folder = "/foo/bar"`, then
`path.start_with?(folder)` would return `true`, but `path` is not under
the `folder` directory.

This commit fixes the problem by matching `folder` to any of the parent
directories of `path` by using the `Pathname#ascend` method to get all
parent directory prefixes of a `path`.
@paracycle paracycle force-pushed the uk-fix-directory-comparison branch from 691e369 to 1a68dcc Compare September 16, 2022 22:53
@paracycle paracycle merged commit 95d76a4 into main Sep 18, 2022
@paracycle paracycle deleted the uk-fix-directory-comparison branch September 18, 2022 17:57
@shopify-shipit shopify-shipit bot temporarily deployed to production September 29, 2022 19:17 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'Cannot find gem' when local gem path has same prefix as project
2 participants