MemoryRepo does not show refs

26 views
Skip to first unread message

Yoelvis Oses

unread,
Nov 29, 2022, 6:14:30 PM11/29/22
to dulwich-discuss

I am working in a project where I have to simulate a local git instance and being able to push files to remote repositories in Azure, GitLab, BitBucket.

Working in OSX, Python 3.8 and installed dulwich=0.2.50. I have been trying to replicate this example: https://github.com/jelmer/dulwich/blob/master/examples/memoryrepo.py
..............................................................................................................
local_repo = MemoryRepo()
local_repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/master')
print(local_repo.refs.as_dict())

porcelain.fetch(local_repo, sys.argv[1])
local_repo['refs/heads/master'] = local_repo['refs/remotes/origin/master']
..............................................................................................................
Issues:
set_symbolic_ref() seems not having effect, since printing refs in next line returns {}, if I try to print refs after FETCH, it is empty yet (fetch is returning remote refs if I print it). Last line here is giving a KeyError since no refs in local repo, similar lines in this example is failing for same reason.

b'HEAD' does not exist in local repo.

Jelmer Vernooij

unread,
Nov 29, 2022, 6:38:48 PM11/29/22
to Yoelvis Oses, dulwich-discuss
porcelain.fetch() returns the remote refs, it does not update them in the repository you're fetching into.

--
You received this message because you are subscribed to the Google Groups "dulwich-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dulwich-discu...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/dulwich-discuss/9f751130-d92b-481d-9fef-901dbdeb516en%40googlegroups.com.

Yoelvis Oses

unread,
Nov 29, 2022, 6:43:46 PM11/29/22
to dulwich-discuss
Is there any other method that updated them into local repository? What about set_symbolic_ref(), why I don't have other expected refs in local repository for this example?

Jelmer Vernooij

unread,
Nov 29, 2022, 6:47:21 PM11/29/22
to Yoelvis Oses, dulwich-discuss
It will update refs/remotes/<remote-name>/<branch> if you specify a remote name (e.g. "origin") rather than a URL.

The symbolic ref you've created is a dead end, since refs/origin/master does not exist.

Yoelvis Oses

unread,
Nov 29, 2022, 7:05:37 PM11/29/22
to Jelmer Vernooij, dulwich-discuss
Well, I can understand the FETCH suggestion, it expects REMOTE_LOCATION and REMOTE_NAME but I did not add symbolic_ref() lines either, I am just following this example (https://github.com/jelmer/dulwich/blob/master/examples/memoryrepo.py). The question is why it fails due to missing refs.

Jelmer Vernooij

unread,
Nov 30, 2022, 6:30:24 AM11/30/22
to Yoelvis Oses, dulwich-discuss
Looking at the example in more detail, I guess it has regressed - it's python2-specific. I'll see if I can update it later this week.

Yoelvis Oses

unread,
Nov 30, 2022, 12:32:39 PM11/30/22
to dulwich-discuss
Thanks Jelmer,
Based in your knowledge as creator, do you think I can accomplish my goals?
Goals: 
   1. being able to simulate a local git instance (trying to avoid cloning) and able to push files to repositories on Azure, AWS CodeCommit, GitLab and Bitbucket using porcelain methods.
   2. being able to grab files from those repositories.
   3. Creating branches, tags in those repositories, maybe through "dulwich.client".
   4. Authenticate with those repositories using Oath, code shows basic authentication but I could authenticate to Azure using Personal Authentication Token.

Thanks for you support.

Jelmer Vernooij

unread,
Dec 1, 2022, 2:02:49 PM12/1/22
to Yoelvis Oses, dulwich-discuss
Hi Yoelvis,

On Wed, 30 Nov 2022 at 17:32, Yoelvis Oses <yos...@gmail.com> wrote:
Thanks Jelmer,
Based in your knowledge as creator, do you think I can accomplish my goals?
Goals: 
   1. being able to simulate a local git instance (trying to avoid cloning) and able to push files to repositories on Azure, AWS CodeCommit, GitLab and Bitbucket using porcelain methods.
I'm not sure what you mean by "simulate". Using memoryrepo like this example does also involves making a clone, just in memory. There's no way around this with the git protocol.
 
   2. being able to grab files from those repositories.
This will require a clone - git's protocol doesn't have a way of fetching individual files.
 
   3. Creating branches, tags in those repositories, maybe through "dulwich.client".
So long as you're just modifying refs, this works. If you're eg. adding new commits you'll need to do a clone (either in memory or on disk).
 
   4. Authenticate with those repositories using Oath, code shows basic authentication but I could authenticate to Azure using Personal Authentication Token.
Bearer tokens should work.

Cheers,

Jelmer
 

Jelmer Vernooij

unread,
Dec 1, 2022, 4:02:32 PM12/1/22
to Yoelvis Oses, dulwich-discuss
I've pushed a fixed version of memoryrepo.py to the git repository.
Reply all
Reply to author
Forward
0 new messages