Skip to content

Implement relative path handling for plugin paths#9299

Open
hsbt wants to merge 2 commits intomasterfrom
fix-gh-3340
Open

Implement relative path handling for plugin paths#9299
hsbt wants to merge 2 commits intomasterfrom
fix-gh-3340

Conversation

@hsbt
Copy link
Member

@hsbt hsbt commented Feb 3, 2026

What was the end-user or developer problem that led to this PR?

Fixes #3340

What is your fix for the problem, implemented in this PR?

Use relative path for plugin directory and expand it to absolute path in bundler internal.

This implementation is a bit of redundant. I'm working to make more smaller code.

Make sure the following tasks are checked

Copilot AI review requested due to automatic review settings February 3, 2026 09:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements relative path handling for bundler plugin paths to fix an issue where changing a username breaks bundler plugins. Previously, plugin paths were stored as absolute paths in the index file, which became invalid when the user's home directory path changed (e.g., from /Users/oldname to /Users/newname).

Changes:

  • Plugin paths and load paths are now stored relative to the plugin root directory in the index file
  • Paths are automatically converted between relative (for storage) and absolute (for runtime) formats
  • Added comprehensive test coverage for the new path handling functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
bundler/lib/bundler/plugin/index.rb Implements path relativization/absolutization logic with helper methods; updates load_index to convert relative paths to absolute at load time, and save_index to store paths as relative
bundler/spec/bundler/plugin/index_spec.rb Adds test coverage verifying that paths are stored relatively and correctly expanded when the plugin root changes (e.g., after a username change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 236 to 246
def relativize_path(path, base)
pathname = Pathname.new(path)
return path unless pathname.absolute?

base_path = Pathname.new(base)
if pathname.to_s.start_with?(base_path.to_s + "/")
pathname.relative_path_from(base_path).to_s
else
path
end
end
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relativize_path method doesn't handle ArgumentError that can be raised by relative_path_from on Windows when paths are on different drives. Other parts of the codebase (e.g., bundler/lib/bundler/shared_helpers.rb:228-233) rescue this exception and return the original path. Consider adding similar error handling here to ensure cross-platform compatibility.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing username breaks bundler plugins

1 participant