30000
  B   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þ[dn¬Ü¢#á�a	HçÂ„ZÁ_ŠI|¥�+Wé3ž¯ÁÀ ?÷     # Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Tests from fetching from git into bzr."""

from dulwich.objects import (
    Blob,
    Tag,
    Tree,
    S_IFGITLINK,
    )
from dulwich.repo import (
    Repo as GitRepo,
    )
import os
import stat
import time

from ... import (
    osutils,
    )
from ...bzr import (
    knit,
    versionedfile,
    )
from ...branch import (
    Branch,
    )
from ...controldir import (
    ControlDir,
    )
from ...bzr.inventory import (
    Inventory,
    )
from ...repository import (
    Repository,
    )
from ...tests import (
    TestCaseWithTransport,
    )

from ..fetch import (
    import_git_blob,
    import_git_tree,
    import_git_submodule,
    )
from ..mapping import (
    BzrGitMappingv1,
    DEFAULT_FILE_MODE,
    )
from . import (
    GitBranchBuilder,
    )


class RepositoryFetchTests:

    def make_git_repo(self, path):
        os.mkdir(path)
        return GitRepo.init(os.path.abspath(path))

    def clone_git_repo(self, from_url, to_url, revision_id=None):
        oldrepos = self.open_git_repo(from_url)
        dir = ControlDir.create(to_url)
        newrepos = dir.create_repository()
        oldrepos.copy_content_into(newrepos, revision_id=revision_id)
        return newrepos

    def test_empty(self):
        self.make_git_repo("d")
        newrepos = self.clone_git_repo("d", "f")
        self.assertEqual([], newrepos.all_revision_ids())

    def make_onerev_branch(self):
        self.make_git_repo("d")
        os.chdir("d")
        bb = GitBranchBuilder()
        bb.set_file("foobar", b"foo\nbar\n", False)
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
        gitsha = bb.finish()[mark]
        os.chdir("..")
        return "d", gitsha

    def test_single_rev(self):
        path, gitsha = self.make_onerev_branch()
        oldrepo = self.open_git_repo(path)
        newrepo = self.clone_git_repo(path, "f")
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
        self.assertEqual([revid], newrepo.all_revision_ids())

    def test_single_rev_specific(self):
        path, gitsha = self.make_onerev_branch()
        oldrepo = self.open_git_repo(path)
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
        newrepo = self.clone_git_repo(path, "f", revision_id=revid)
        self.assertEqual([revid], newrepo.all_revision_ids())

    def test_incremental(self):
        self.make_git_repo("d")
        os.chdir("d")
        bb = GitBranchBuilder()
        bb.set_file("foobar", b"foo\nbar\n", False)
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
        bb.set_file("foobar", b"fooll\nbar\n", False)
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"nextmsg")
        marks = bb.finish()
        gitsha1 = marks[mark1]
        gitsha2 = marks[mark2]
        os.chdir("..")
        oldrepo = self.open_git_repo("d")
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
        newrepo = self.clone_git_repo("d", "f", revision_id=revid1)
        self.assertEqual([revid1], newrepo.all_revision_ids())
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
        newrepo.fetch(oldrepo, revision_id=revid2)
        self.assertEqual({revid1, r