Title: Adding files to repository that is located directly in the root · Issue #743 · gitpython-developers/GitPython · GitHub
Open Graph Title: Adding files to repository that is located directly in the root · Issue #743 · gitpython-developers/GitPython
X Title: Adding files to repository that is located directly in the root · Issue #743 · gitpython-developers/GitPython
Description: This is a weird scenario, but if you init git repo in the root directory(e.g. D:\) and try to add a file using gitpython, it will throw a ValueError: Absolute path `D:\\file` is not in git repository at `D:\\` The reason for this is impr...
Open Graph Description: This is a weird scenario, but if you init git repo in the root directory(e.g. D:\) and try to add a file using gitpython, it will throw a ValueError: Absolute path `D:\\file` is not in git reposito...
X Description: This is a weird scenario, but if you init git repo in the root directory(e.g. D:\) and try to add a file using gitpython, it will throw a ValueError: Absolute path `D:\\file` is not in git reposito...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/743
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding files to repository that is located directly in the root","articleBody":"This is a weird scenario, but if you init git repo in the root directory(e.g. D:\\\\) and try to add a file using gitpython, it will throw a ValueError:\r\n```\r\nAbsolute path `D:\\\\file` is not in git repository at `D:\\\\`\r\n```\r\nThe reason for this is improper validation in _to_relative_path method located at git/index/base.py:\r\n```\r\n def _to_relative_path(self, path):\r\n \"\"\":return: Version of path relative to our git directory or raise ValueError\r\n if it is not within our git direcotory\"\"\"\r\n if not osp.isabs(path):\r\n return path\r\n if self.repo.bare:\r\n raise InvalidGitRepositoryError(\"require non-bare repository\")\r\n relative_path = path.replace(self.repo.working_tree_dir + os.sep, \"\")\r\n if relative_path == path:\r\n raise ValueError(\"Absolute path %r is not in git repository at %r\" % (path, self.repo.working_tree_dir))\r\n return relative_path\r\n```\r\nI.e. when path is `/file` and working_tree_dir is `/`, relative_path stays equal to path, because `self.repo.working_tree + os.sep` is equal to `//`. The way to solve this is to simply use os.path.relpath methond. Please see pull-request attached.","author":{"url":"https://github.com/efiop","@type":"Person","name":"efiop"},"datePublished":"2018-04-03T11:48:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/743/GitPython/issues/743"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cbdd5898-12a6-c15e-7c39-59601f951ed5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3A6:B0660:B54DE1:FE283C:696A1E73 |
| html-safe-nonce | 10f17e53389b9712c37cc4fbfdef24869d85dc88622b6a4f7c303f3341036f7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0E2OkIwNjYwOkI1NERFMTpGRTI4M0M6Njk2QTFFNzMiLCJ2aXNpdG9yX2lkIjoiODU2MDI3MzE1NDQ4NTM5NTA1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8449600f98eff5dc3bc68875da2adee4ad1b241da5eb8c7735cfd0cdf9463c16 |
| hovercard-subject-tag | issue:310803529 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/gitpython-developers/GitPython/743/issue_layout |
| twitter:image | https://opengraph.githubassets.com/518cd7cec4efb2d90025b90f55342b1b7d0aecb0f6db78b4bbef4c755a443a3d/gitpython-developers/GitPython/issues/743 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/518cd7cec4efb2d90025b90f55342b1b7d0aecb0f6db78b4bbef4c755a443a3d/gitpython-developers/GitPython/issues/743 |
| og:image:alt | This is a weird scenario, but if you init git repo in the root directory(e.g. D:\) and try to add a file using gitpython, it will throw a ValueError: Absolute path `D:\\file` is not in git reposito... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | efiop |
| hostname | github.com |
| expected-hostname | github.com |
| None | 014f3d193f36b7d393f88ca22d06fbacd370800b40a547c1ea67291e02dc8ea3 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d515f6f09fa57a93bf90355cb894eb84ca4f458f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width