Example #1
0
    def collection_post(self):
        """Initialise a new git repository, or clone from an existing repo."""
        repo_path = extract_json_data(self.request).get("repo_path")
        clone_path = extract_json_data(self.request).get("clone_from")
        clone_refs = extract_json_data(self.request).get("clone_refs", False)

        if not repo_path:
            self.request.errors.add("body", "repo_path", "repo_path is missing")
            return
        repo = os.path.join(self.repo_store, repo_path)
        if not is_valid_path(self.repo_store, repo):
            self.request.errors.add("body", "name", "invalid path.")
            raise exc.HTTPNotFound()

        if clone_path:
            repo_clone = os.path.join(self.repo_store, clone_path)
        else:
            repo_clone = None

        try:
            new_repo_path = store.init_repo(repo, clone_from=repo_clone, clone_refs=clone_refs)
            repo_name = os.path.basename(os.path.normpath(new_repo_path))
            return {"repo_url": "/".join([self.request.url, repo_name])}
        except GitError:
            return exc.HTTPConflict()  # 409
Example #2
0
 def test_repo_alternates_objects_shared(self):
     """Ensure objects are shared from alternate repo."""
     factory = RepoFactory(self.repo_path)
     commit_oid = factory.add_commit("foo", "foobar.txt")
     new_repo_path = os.path.join(self.repo_store, uuid.uuid4().hex)
     repo_path_with_alt = store.init_repo(new_repo_path, alternate_repo_paths=[factory.repo.path])
     repo_with_alt = open_repo(repo_path_with_alt)
     self.assertEqual(commit_oid.hex, repo_with_alt.get(commit_oid).hex)
Example #3
0
    def test_repo_config(self):
        """Assert repository is initialised with correct config defaults."""
        repo_path = store.init_repo(self.repo_path)
        repo_config = pygit2.Repository(repo_path).config
        yaml_config = yaml.load(open("git.config.yaml"))

        self.assertEqual(bool(yaml_config["core.logallrefupdates"]), bool(repo_config["core.logallrefupdates"]))
        self.assertEqual(str(yaml_config["pack.depth"]), repo_config["pack.depth"])
Example #4
0
    def test_clone_without_refs(self):
        self.makeOrig()
        self.assertAllLinkCounts(1, self.orig_objs)

        # init_repo with clone_from=orig and clone_refs=False creates a
        # repo without any refs, but the objects are copied.
        to_path = os.path.join(self.repo_store, "to/")
        store.init_repo(to_path, clone_from=self.orig_path, clone_refs=False)
        to = pygit2.Repository(to_path)
        self.assertIsNot(None, to[self.master_oid])
        self.assertEqual([], to.listall_references())

        # Internally, the packs are hardlinked into a subordinate
        # alternate repo, so minimal space is used by the clone.
        self.assertTrue(os.path.exists(os.path.join(to_path, "turnip-subordinate")))
        self.assertAllLinkCounts(2, self.orig_objs)

        # No refs exist, but receive-pack advertises the clone_from's
        # refs as extra haves.
        self.assertAdvertisedRefs([(".have", self.master_oid.hex)], ["refs/"], to_path)
Example #5
0
    def test_clone_with_refs(self):
        self.makeOrig()
        self.assertAllLinkCounts(1, self.orig_objs)

        # init_repo with clone_from=orig and clone_refs=True creates a
        # repo with the same set of refs. And the objects are copied
        # too.
        to_path = os.path.join(self.repo_store, "to/")
        store.init_repo(to_path, clone_from=self.orig_path, clone_refs=True)
        to = pygit2.Repository(to_path)
        self.assertIsNot(None, to[self.master_oid])
        self.assertEqual(self.orig_refs, to.listall_references())

        # Internally, the packs are hardlinked into a subordinate
        # alternate repo, so minimal space is used by the clone.
        self.assertTrue(os.path.exists(os.path.join(to_path, "turnip-subordinate")))
        self.assertAllLinkCounts(2, self.orig_objs)

        self.assertAdvertisedRefs(
            [(".have", self.master_oid.hex), ("refs/heads/master", self.master_oid.hex)], [], to_path
        )
Example #6
0
 def test_repo_with_alternates(self):
     """Ensure objects path is defined correctly in repo alternates."""
     factory = RepoFactory(self.repo_path)
     new_repo_path = os.path.join(self.repo_store, uuid.uuid1().hex)
     repo_path_with_alt = store.init_repo(new_repo_path, alternate_repo_paths=[factory.repo.path])
     self.assert_alternate_exists(factory.repo.path, repo_path_with_alt)
Example #7
0
 def test_from_scratch(self):
     path = os.path.join(self.repo_store, "repo/")
     self.assertEqual(path, store.init_repo(path))
     r = pygit2.Repository(path)
     self.assertEqual([], r.listall_references())