Skip to content

Empty (bare) repository causes error #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
progval opened this issue Apr 1, 2012 · 4 comments
Closed

Empty (bare) repository causes error #55

progval opened this issue Apr 1, 2012 · 4 comments

Comments

@progval
Copy link

progval commented Apr 1, 2012

Hi,

I cannot instanciate a Repo object with a bare repository:

progval@Andromede:~/repositories$ python
Python 2.7.3rc2 (default, Mar 21 2012, 06:59:11) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> git.Repo('testing.git').tree()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/git/repo/base.py", line 399, in tree
    return self.head.commit.tree
  File "/usr/local/lib/python2.7/dist-packages/git/refs/symbolic.py", line 168, in _get_commit
    obj = self._get_object()
  File "/usr/local/lib/python2.7/dist-packages/git/refs/symbolic.py", line 161, in _get_object
    return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
  File "/usr/local/lib/python2.7/dist-packages/git/refs/symbolic.py", line 115, in dereference_recursive
    hexsha, ref_path = cls._get_ref_info(repo, ref_path)
  File "/usr/local/lib/python2.7/dist-packages/git/refs/symbolic.py", line 142, in _get_ref_info
    raise ValueError("Reference at %r does not exist" % ref_path)
ValueError: Reference at 'refs/heads/master' does not exist

Regards,
Valentin Lorentz

@Byron
Copy link
Member

Byron commented Apr 19, 2012

Hi Valentin,

Can you access the repo with the git commandline ?
Does the file refs/heads/master exist in your repository on in your packed-refs file ?

Thanks for the info.

@progval
Copy link
Author

progval commented Apr 20, 2012

The repo I was using had no commit. With another one, it works.

Thank you

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

@Byron
Copy link
Member

Byron commented Apr 21, 2012

Alright, that explains it ! It does not check for the 'repo without commit' case yet.
Once it has a commit, it should work as the branch HEAD points to actually exists.

@Byron Byron added this to the v0.3.5 - bugfixes milestone Nov 19, 2014
Byron added a commit that referenced this issue Jan 8, 2015
Helps to clarify #55
@Byron
Copy link
Member

Byron commented Jan 8, 2015

The issue is somewhat misleading, as not the instantiation of the repository is causing an error, but the call to tree() right afterwards. Considering that in an empty repository, there is no commit being pointed to, and thus, no tree, failing in some way is expected.
The exception you see is expected, and I have added this particular call to the test-suite.

In future, and if empty repositories have to be handled, you could check if the branch you see is valid, such as in

repo.active_branch.is_valid()

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

No branches or pull requests

2 participants