librelist archives

« back to archive

pygit2/libgit2 : resolve_reference('config')

pygit2/libgit2 : resolve_reference('config')

From:
Han-Wen Nienhuys
Date:
2012-03-27 @ 16:34
What is the correct way (using libgit2/pygit2) to resolve branches
similar to how git does this?

>>> import pygit2 as p
>>> r =p.Repository('..')
>>> r.lookup_reference('does-not-exist')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'does-not-exist'

>>> r.lookup_reference('config')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pygit2.GitError: config: Failed to lookup reference
	- Failed to lookup reference
	- Failed to lookup reference from packfile


my current code tries '' , 'refs/heads/' , 'refs/tags/',
'refs/remotes/' in this order as prefixes.  This has the side effect
of getting very confused when trying to lookup a branch with the same
name  (such .git/config).

-- 
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen

Re: [libgit2] pygit2/libgit2 : resolve_reference('config')

From:
J. David Ibanez
Date:
2012-03-29 @ 20:41
The error message should be the same in both cases. Could you help
to track down where is the problem? or at least open an issue in the
pygit2 tracker?

Otherwise I think the API is fine.



On Tue, 27 Mar 2012 13:34:26 -0300
Han-Wen Nienhuys <hanwenn@gmail.com> wrote:

> What is the correct way (using libgit2/pygit2) to resolve branches
> similar to how git does this?
> 
> >>> import pygit2 as p
> >>> r =p.Repository('..')
> >>> r.lookup_reference('does-not-exist')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> KeyError: 'does-not-exist'
> 
> >>> r.lookup_reference('config')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> pygit2.GitError: config: Failed to lookup reference
> 	- Failed to lookup reference
> 	- Failed to lookup reference from packfile
> 
> 
> my current code tries '' , 'refs/heads/' , 'refs/tags/',
> 'refs/remotes/' in this order as prefixes.  This has the side effect
> of getting very confused when trying to lookup a branch with the same
> name  (such .git/config).
> 



-- 
J. David Ibáñez
Itaapy <http://www.itaapy.com>         Tel +33 (0)1 42 23 67 45
9 rue Darwin, 75018 Paris              Fax +33 (0)1 53 28 27 88

Re: pygit2/libgit2 : resolve_reference('config')

From:
Han-Wen Nienhuys
Date:
2012-03-27 @ 16:35
This looks like a bug: shouldn't libgit check that the file starts
with 'ref: ' ?

On Tue, Mar 27, 2012 at 1:34 PM, Han-Wen Nienhuys <hanwenn@gmail.com> wrote:
> What is the correct way (using libgit2/pygit2) to resolve branches
> similar to how git does this?
>
>>>> import pygit2 as p
>>>> r =p.Repository('..')
>>>> r.lookup_reference('does-not-exist')
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> KeyError: 'does-not-exist'
>
>>>> r.lookup_reference('config')
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> pygit2.GitError: config: Failed to lookup reference
>        - Failed to lookup reference
>        - Failed to lookup reference from packfile
>
>
> my current code tries '' , 'refs/heads/' , 'refs/tags/',
> 'refs/remotes/' in this order as prefixes.  This has the side effect
> of getting very confused when trying to lookup a branch with the same
> name  (such .git/config).
>
> --
> Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen



-- 
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen