Title: Support relative worktree paths (git 2.48+ worktree.useRelativePaths) by elovelan · Pull Request #2151 · gitpython-developers/GitPython · GitHub
Open Graph Title: Support relative worktree paths (git 2.48+ worktree.useRelativePaths) by elovelan · Pull Request #2151 · gitpython-developers/GitPython
X Title: Support relative worktree paths (git 2.48+ worktree.useRelativePaths) by elovelan · Pull Request #2151 · gitpython-developers/GitPython
Description: Summary Git 2.48 introduced the worktree.useRelativePaths config option. When enabled, git worktree add writes a relative gitdir: into the worktree's .git file — relative to the directory containing that .git file. GitPython's Repo.__init__ previously passed the value of that gitdir: line straight through expand_path, which calls os.path.abspath against the process's current working directory rather than against the worktree. Using the library when the cwd was not the worktree root therefore failed. This change resolves the relative gitdir against curpath (the directory containing the .git file) before expanding. Absolute paths — i.e. the pre-2.48 default — are unaffected, because os.path.join ignores its first argument when the second is absolute. This change also includes a minor doc fix that I came across when trying to better understand how git is called. Test plan New test TestRepo.test_git_work_tree_dotgit_relative, which delegates to test_git_work_tree_dotgit but runs git worktree add --relative-paths. I verified that the test failed before implementation and now passes. Existing test_git_work_tree_dotgit still passes, confirming absolute-path worktrees are unaffected. AI disclosure Per CONTRIBUTING.md: this PR description and the commit message were drafted by Claude Code on behalf of @elovelan; though the final versions were manually reworded for clarity. All code was written without AI (didn't start that way but I didn't like its test implementation, and the actual implementation was trivial).
Open Graph Description: Summary Git 2.48 introduced the worktree.useRelativePaths config option. When enabled, git worktree add writes a relative gitdir: into the worktree's .git file — relative to the directory conta...
X Description: Summary Git 2.48 introduced the worktree.useRelativePaths config option. When enabled, git worktree add writes a relative gitdir: into the worktree's .git file — relative to the directory c...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/2151
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f87d9804-b3a7-e428-0a23-a9d11a4d91b0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D068:2CDA4:8011AF:8398AA:6A59EE68 |
| html-safe-nonce | 9f8b39558daa4eba68f420aab05a5ec3032dea0850eb252e6424d731801cf75d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDY4OjJDREE0OjgwMTFBRjo4Mzk4QUE6NkE1OUVFNjgiLCJ2aXNpdG9yX2lkIjoiNzkyMjE0NDY1MTg3NjM2Mzg4MCIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | aaafe0d94752c29d0cada545a85c0540158ef6ec9752a4473b89ce8bf3160f20 |
| hovercard-subject-tag | pull_request:3671415349 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/2151/files |
| twitter:image | https://avatars.githubusercontent.com/u/563397?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/563397?s=400&v=4 |
| og:image:alt | Summary Git 2.48 introduced the worktree.useRelativePaths config option. When enabled, git worktree add writes a relative gitdir: into the worktree's .git file — relative to the directory conta... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32bf0b7849e1b6561059cca2cb03568251960859 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width