From aaf0c55b62e6f4833f7c27559940434dd9663426 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 17 2015 08:52:54 +0000 Subject: Clone all the remote branches when cloning a project Currently, cloning a project meant only cloning the master branch. With this change, all the branches present in the main project will be cloned in the fork as well. Note: we could use the --mirror recipe from: https://github.com/libgit2/pygit2/blob/master/docs/recipes/git-clone-mirror.rst But this works only for pygit2 0.22+ while we want to work with 0.21 as well. --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 98f0364..cb2c63a 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1022,7 +1022,14 @@ def fork_project(session, user, repo, gitfolder, # Make sure we won't have SQLAlchemy error before we create the repo session.flush() - pygit2.clone_repository(reponame, forkreponame, bare=True) + frepo = pygit2.clone_repository(reponame, forkreponame, bare=True) + # Clone all the branches as well + for branch in frepo.listall_branches(pygit2.GIT_BRANCH_REMOTE): + if branch == 'origin/master': + continue + br = frepo.lookup_branch(branch, pygit2.GIT_BRANCH_REMOTE) + name = br.branch_name.replace(br.remote_name, '')[1:] + frepo.create_branch(name, frepo.get(br.target.hex)) docrepo = os.path.join(docfolder, project.path) if os.path.exists(docrepo):