Gitpython: git.Repo InvalidGitRepositoryError

Created on 9 Feb 2015  路  3Comments  路  Source: gitpython-developers/GitPython

Previously when using GitPython 0.3.2c1 we had something that would point to a sub directory in a repo:

repo = git.Repo(os.path.dirname('/path/to/repo/sub_dir'))

Now after upgrading to GitPython 0.3.6 I am getting this error:

Traceback (most recent call last):
  File "/path/to/repo/sub_dir/perc_version", line 685, in <module>
    main()
  File "/path/to/repo/sub_dir/perc_version", line 567, in main
    perc_lib.fail_if_outdated()
  File "/path/to/repo/sub_dir/lib.py", line 451, in fail_if_outdated
    repo = git.Repo(os.path.dirname(command_path))
  File "/usr/local/lib/python2.7/site-packages/git/repo/base.py", line 162, in __init__
    raise InvalidGitRepositoryError(epath)
git.exc.InvalidGitRepositoryError: /path/to/repo/sub_dir

I can fix by adding another os.path.dirname but should this be the behavior for git.Repo to need the top level of a repo or a bug?

waiting for feedback acknowledged

Most helpful comment

This is related to a bug-fix actually. To get the old behaviour, you can instantiate your Repo object with Repo(path, search_parent_directories=True).

The change was noted in the changelog for v0.3.5.

Please let me know if this fixes your issue.

All 3 comments

This is related to a bug-fix actually. To get the old behaviour, you can instantiate your Repo object with Repo(path, search_parent_directories=True).

The change was noted in the changelog for v0.3.5.

Please let me know if this fixes your issue.

Yes, that fixes it. Thanks @Byron!

i got the same error as OP when trying to make a git.Repo from a subdir of a git repo. this thread solved it for me. Namely,

Repo(search_parent_directories=True)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jon-armstrong picture jon-armstrong  路  7Comments

connordelacruz picture connordelacruz  路  5Comments

niso120b picture niso120b  路  4Comments

sp-ricard-valverde picture sp-ricard-valverde  路  3Comments

olethanh picture olethanh  路  6Comments