0

How on earth does one get the index for a repos using GitPython ?

import git

repo = git.Repo.init('/path/to/repos/')
... add some files ...
... commit ...
index = repo.index()

Throw error: 'Repo' object has no attribute 'index'

WTH? My eyes are bloody from reading the Trier tutorial over and over getting nowhere fast. Clues anyone ?

RSAdmin
  • 419
  • 1
  • 6
  • 20

1 Answers1

2

There are two issues here. First, index isn't method, it's an IndexFile object. Secondly, I wonder if you're not using the current version of GitPython.

If I start with:

$ virtualenv stacktest
$ ./stacktext/bin/pip install GitPython
$ ./stackext/bin/python
Python 2.7.5 (default, Nov 12 2013, 16:18:42) 
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> repo = git.Repo.init('/home/username/projects/myproject')
>>> repo.index
<git.index.base.IndexFile object at 0x1213a48>
>>> repo.index.entries
{('README.md', 0): (100644, 515cbd1e78aa13ec91941eaa63ecec89d5e4b947, 0, README.md), ('setup.py', 0): (100644, 7497e295447af70a6865b7313bfb2f86ba6577d6, 0, setup.py)}

Another possibility is that something in your code is masking the attribute. If you can post an actual runnable code sampe that someone else can run, that will help narrow down the problem.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • I thinkn you may have hit it in one: `pip freeze` shows me GitPython == 0.1.7. For some reason that is all that pip install will give me. Running easy_installl GitPython gets me up to date. – RSAdmin Jan 20 '14 at 03:45