Skip to content

test_index_mutation compares full dereferenced and non-dereferenced paths #224

Description

@yarikoptic
======================================================================
ERROR: test_index_mutation (git.test.test_index.TestIndex)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/python-git/git/test/lib/helper.py", line 112, in repo_creator
    return func(self, rw_repo)
  File "/home/yoh/deb/gits/python-git/git/test/test_index.py", line 482, in test_index_mutation
    [os.path.abspath(os.path.join('lib', 'git', 'head.py'))] * 2, fprogress=self._fprogress_add)
  File "/home/yoh/deb/gits/python-git/git/index/base.py", line 684, in add
    paths, entries = self._preprocess_add_items(items)
  File "/home/yoh/deb/gits/python-git/git/index/base.py", line 546, in _preprocess_add_items
    paths.append(self._to_relative_path(item))
  File "/home/yoh/deb/gits/python-git/git/index/base.py", line 536, in _to_relative_path
    raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))
ValueError: Absolute path '/tmp/tmpX75gjinon_bare_test_index_mutation/lib/git/head.py' is not in git repository at '/home/yoh/.tmp/tmpX75gjinon_bare_test_index_mutation'

since I have

$> ls -ld $TMPDIR
lrwxrwxrwx 1 yoh yoh 5 Nov 10  2010 /home/yoh/.tmp -> /tmp//

so may be in_to_relative_path should deref both paths before comparison?

Activity

  1. added this to the v0.3.5 - bugfixes milestone on Jan 5, 2015
  2. Byron commented on Jan 5, 2015

    @Byron
    Member

    It would be worth investigating where the path-mismatch is introduced. This is exactly where it's fixed ideally.
    If this is the only failing test on your system due to this issue, I would be somewhat relieved though.

  3. yarikoptic commented on Jan 5, 2015

    @yarikoptic
    ContributorAuthor

    it is coming from the use of abspath to obtain absolute path for a local file

    $> git grep -2 abspath git/test/test_index.py 
    git/test/test_index.py-        # same file
    git/test/test_index.py-        entries = index.reset(new_commit).add(
    git/test/test_index.py:            [os.path.abspath(os.path.join('lib', 'git', 'head.py'))] * 2, fprogress=self._fprogress_add)
    git/test/test_index.py-        self._assert_entries(entries)
    git/test/test_index.py-        assert entries[0].mode & 0o644 == 0o644
    

    IIRC, at some point I have looked into this issue, and there were no reliable way to obtain un-dereferenced current directory to then create "abspath" without actually dereferencing the path. Apparently IIRC it is more of a 'shell gimmick' to know that it is e.g. under ~/.tmp instead of physically being under /tmp (as OS would report, and thus abspath and getcwd). So I wondered if it might be worth dereferencing repo.working_tree_dir from the beginning. I see already a use of os.path.realpath in read_gitfile ...

    I have some other failures still but I believe they are not related to this one

  4. self-assigned this
    on Jan 12, 2015
  5. Byron commented on Jan 12, 2015

    @Byron
    Member

    All tests should work natively now even with a symbolic link as TMPDIR. My solution is to not use realpath at all, but instead operate on paths consistently. That should save the IOPs otherwise necessary to obtain such a realpath (which as to read and follow symlinks).

  6. Byron commented on Jan 12, 2015

    @Byron
    Member

    Videos can be found here:

  7. yarikoptic commented on Jan 12, 2015

    @yarikoptic
    ContributorAuthor

    OMG -- I am in a movie! ;) Quite cool of you to produce those -- I didn't know, quite a nice idea, may be the *net will hear my angry russian cursing at some point as well ;)

  8. ryneeverett commented on Feb 22, 2015

    @ryneeverett

    @Byron I'm confused by your conclusion that os.path.realpath "wasn't required afterall" in ede325d.

    43e430d seems to be the only commit that doesn't throw the above ValueError when a non-normalized absolute path is added to the index. E.g.:

    >>> my_path = '/home/user/./repo/file'
    >>> os.path.isabs(my_path)
    True
    >>> repo.index.add([my_path])
    ...
    ValueError: Absolute path '/home/user/./repo/file' is not in git repository at '/home/user/repo'
    >>> my_path = os.path.realpath(my_path)
    >>> repo.index.add([my_path])
    <success>

    Obviously I can work around this by normalizing my own path strings as above, but is this the expected behavior?

  9. Byron commented on Feb 22, 2015

    @Byron
    Member

    I would still state that realpath isn't required. In your case, normpathis advised and it should work. In the recording, I might have come to the conclusion that application should sanitise their paths themselves, gitpython seems sufficiently low-level to be able to expect that.
    This is just my current opinion though, and if you want to make a statement towards including normpath in the index implementation, I could certainly do so.

  10. ryneeverett commented on Feb 22, 2015

    @ryneeverett

    @Byron True. I'd like to at least see it stated in the API reference that paths need to be normalized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions