GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adding files to repository that is located directly in the root · Issue #743 · gitpython-developers/GitPython

Adding files to repository that is located directly in the root #743

New issue
Copy link
New issue
Copy link
Closed
Closed
Adding files to repository that is located directly in the root#743
Copy link
Labels
acknowledged
Milestone
v2.1.10 - Bugfixes

Description

@efiop
efiop
opened on Apr 3, 2018
Issue body actions

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 improper validation in _to_relative_path method located at git/index/base.py:

    def _to_relative_path(self, path):
        """:return: Version of path relative to our git directory or raise ValueError
        if it is not within our git direcotory"""
        if not osp.isabs(path):
            return path
        if self.repo.bare:
            raise InvalidGitRepositoryError("require non-bare repository")
        relative_path = path.replace(self.repo.working_tree_dir + os.sep, "")
        if relative_path == path:
            raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))
        return relative_path

I.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.

Activity

  1. efiop
    added 6 commits that reference this issue on Apr 3, 2018

    git: index: base: use os.path.relpath

    This issue will close once commit 6fa24ef is merged into the 'master' branch.
    6fa24ef

    git: index: base: use os.path.relpath

    This issue will close once commit 450faa8 is merged into the 'master' branch.
    450faa8

    git: index: base: use os.path.relpath

    This issue will close once commit ef6453c is merged into the 'master' branch.
    ef6453c

    git: index: base: use os.path.relpath

    This issue will close once commit 91846f2 is merged into the 'master' branch.
    91846f2

    git: index: base: use os.path.relpath

    This issue will close once commit 97164b0 is merged into the 'master' branch.
    97164b0

    git: index: base: use os.path.relpath

    This issue will close once commit 176474b is merged into the 'master' branch.
    176474b
  2. Byron
    added
    acknowledged
    on Apr 3, 2018
  3. Byron commented on Apr 3, 2018

    @Byron
    Byron
    on Apr 3, 2018
    Member
    More actions

    Thanks a lot for digging in a providing the fix with the issue :). I am looking forward to closing this one when the review items were addressed.

  4. efiop
    added a commit that references this issue on Apr 3, 2018

    git: index: base: use os.path.relpath

    This issue will close once commit c554ab1 is merged into the 'master' branch.
    c554ab1
  5. efiop commented on Apr 3, 2018

    @efiop
    efiop
    on Apr 3, 2018
    ContributorAuthor
    More actions

    And thank you for the quick feedback!

  6. Byron
    closed this as completedin #744on Apr 4, 2018
  7. Byron
    added a commit that references this issue on Apr 4, 2018

    git: index: base: use os.path.relpath

    This issue will close once commit 0857d33 is merged into the 'main' branch.
    0857d33
  8. Byron
    added this to the v2.1.10 - Bugfixes milestone on Apr 4, 2018
  9. riley-martine
    added a commit that references this issue on Dec 7, 2023

    git: index: base: use os.path.relpath

    This issue will close once commit 1ec43f7 is merged into the 'master' branch.
    1ec43f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledged

    Type

    No type

    Projects

    No projects

      Milestone

      • v2.1.10 - Bugfixes

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.