2018-02-22 05:36:46 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2018-02-22 05:36:46 +03:00
|
|
|
#
|
2019-06-20 02:58:25 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
2018-02-22 05:36:46 +03:00
|
|
|
|
2018-11-14 23:13:46 +03:00
|
|
|
from eden.integration.lib import hgrepo
|
|
|
|
|
2018-02-22 05:36:46 +03:00
|
|
|
from .lib.hg_extension_test_base import EdenHgTestCase, hg_test
|
|
|
|
|
|
|
|
|
2019-08-27 04:47:47 +03:00
|
|
|
@hg_test("Treemanifest", "TreeOnly")
|
2019-08-30 23:28:14 +03:00
|
|
|
# pyre-fixme[13]: Attribute `backing_repo` is never initialized.
|
|
|
|
# pyre-fixme[13]: Attribute `backing_repo_name` is never initialized.
|
|
|
|
# pyre-fixme[13]: Attribute `config_variant_name` is never initialized.
|
|
|
|
# pyre-fixme[13]: Attribute `repo` is never initialized.
|
2018-02-22 05:36:46 +03:00
|
|
|
class PullTest(EdenHgTestCase):
|
2018-11-14 23:13:46 +03:00
|
|
|
server_repo: hgrepo.HgRepository
|
|
|
|
commit1: str
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def create_backing_repo(self) -> hgrepo.HgRepository:
|
2018-02-22 05:36:46 +03:00
|
|
|
# Create a server repository first
|
|
|
|
self.server_repo = self.create_server_repo()
|
|
|
|
|
|
|
|
hgrc = self.get_hgrc()
|
2018-05-10 07:33:49 +03:00
|
|
|
hgrc["paths"] = {"default": self.server_repo.path}
|
|
|
|
repo = self.create_hg_repo("main", hgrc=hgrc)
|
2018-02-22 05:36:46 +03:00
|
|
|
self.populate_backing_repo(repo)
|
|
|
|
return repo
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def populate_backing_repo(self, repo: hgrepo.HgRepository) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
print("creating backing repo")
|
|
|
|
repo.hg("pull")
|
|
|
|
repo.hg("update", self.commit1)
|
2018-02-22 05:36:46 +03:00
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def create_server_repo(self) -> hgrepo.HgRepository:
|
2018-05-10 07:33:49 +03:00
|
|
|
print("creating server repo")
|
2018-02-22 05:36:46 +03:00
|
|
|
# Create a server repository.
|
|
|
|
hgrc = self.get_hgrc()
|
|
|
|
self.apply_hg_config_variant(hgrc)
|
2018-05-10 07:33:49 +03:00
|
|
|
if self.config_variant_name in ("Treemanifest", "TreeOnly"):
|
2018-02-22 05:36:46 +03:00
|
|
|
# fastmanifest must be disabled on the server repository.
|
|
|
|
# The treemanifest server-side code breaks otherwise.
|
2018-05-10 07:33:49 +03:00
|
|
|
hgrc["extensions"]["fastmanifest"] = "!"
|
|
|
|
hgrc["treemanifest"] = {"server": "True", "autocreatetrees": "True"}
|
2018-02-22 05:36:46 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
repo = self.create_hg_repo("server_repo", hgrc=hgrc)
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Create a commit in the server repository
|
2018-05-10 07:33:49 +03:00
|
|
|
repo.write_file("hello.txt", "hola")
|
|
|
|
repo.write_file("foo/bar.txt", "bar contents\n")
|
|
|
|
repo.write_file("foo/test.txt", "test\n")
|
|
|
|
repo.write_file("foo/subdir/test.txt", "test\n")
|
|
|
|
repo.write_file("foo/subdir/main.c", 'printf("hello world\\n");\n')
|
|
|
|
repo.write_file("src/deep/a/b/c/abc.txt", "abc\n")
|
|
|
|
repo.write_file("src/deep/a/b/c/def.txt", "def\n")
|
|
|
|
repo.write_file("src/deep/a/b/c/xyz.txt", "xyz\n")
|
|
|
|
self.commit1 = repo.commit("Initial commit.\n")
|
|
|
|
print("commit1=%s" % (self.commit1,))
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
return repo
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_pull(self) -> None:
|
2018-02-22 05:36:46 +03:00
|
|
|
self.assert_status_empty()
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertEqual("test\n", self.read_file("foo/subdir/test.txt"))
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Create a few new commits on the server
|
2018-05-10 07:33:49 +03:00
|
|
|
self.server_repo.write_file(
|
|
|
|
"foo/subdir/main.c", 'printf("hello world v2!\\n");\n'
|
|
|
|
)
|
2018-11-14 23:13:46 +03:00
|
|
|
commit2 = self.server_repo.commit("Commit 2\n")
|
2018-05-10 07:33:49 +03:00
|
|
|
|
|
|
|
self.server_repo.write_file("foo/test.txt", "updated test\n")
|
|
|
|
self.server_repo.write_file(
|
|
|
|
"foo/subdir/main.c", 'printf("hello world v3!\\n");\n'
|
|
|
|
)
|
|
|
|
self.server_repo.write_file("src/myproject/main.py", 'print("hello")\n')
|
2018-11-14 23:13:46 +03:00
|
|
|
commit3 = self.server_repo.commit("Commit 3\n")
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Run "hg pull" inside the Eden checkout
|
2018-11-17 06:39:20 +03:00
|
|
|
self.repo.run_hg("pull", stdout=None, stderr=None)
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Update the Eden checkout to commit2
|
2018-11-14 23:13:46 +03:00
|
|
|
self.repo.hg("update", commit2)
|
2018-02-22 05:36:46 +03:00
|
|
|
self.assert_status_empty()
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertEqual(
|
|
|
|
'printf("hello world v2!\\n");\n', self.read_file("foo/subdir/main.c")
|
|
|
|
)
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Update the Eden checkout to commit3
|
2018-11-14 23:13:46 +03:00
|
|
|
self.repo.hg("update", commit3)
|
2018-02-22 05:36:46 +03:00
|
|
|
self.assert_status_empty()
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertEqual(
|
|
|
|
'printf("hello world v3!\\n");\n', self.read_file("foo/subdir/main.c")
|
|
|
|
)
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Create a 4th commit on the server
|
2018-05-10 07:33:49 +03:00
|
|
|
self.server_repo.write_file("src/deep/a/b/c/xyz.txt", "xyz2\n")
|
2018-11-14 23:13:46 +03:00
|
|
|
commit4 = self.server_repo.commit("Commit 4\n")
|
2018-02-22 05:36:46 +03:00
|
|
|
|
|
|
|
# Pull and update the Eden checkout to the 4th commit.
|
|
|
|
# This tests that the hg_import_helper can correctly see new data on
|
|
|
|
# the server that was created after it first established its connection
|
|
|
|
# to the server.
|
2018-11-17 06:39:20 +03:00
|
|
|
self.repo.run_hg("pull", stdout=None, stderr=None)
|
2018-11-14 23:13:46 +03:00
|
|
|
self.repo.hg("update", commit4)
|
2018-02-22 05:36:46 +03:00
|
|
|
self.assert_status_empty()
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertEqual(
|
|
|
|
'printf("hello world v3!\\n");\n', self.read_file("foo/subdir/main.c")
|
|
|
|
)
|
|
|
|
self.assertEqual("xyz2\n", self.read_file("src/deep/a/b/c/xyz.txt"))
|