2017-08-25 00:14:56 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2017-08-25 00:14:56 +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.
|
2017-08-25 00:14:56 +03:00
|
|
|
|
|
|
|
import os
|
|
|
|
from textwrap import dedent
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
from eden.integration.lib import hgrepo
|
|
|
|
|
2017-11-08 05:47:42 +03:00
|
|
|
from .lib.hg_extension_test_base import EdenHgTestCase, hg_test
|
2017-08-25 00:14:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
@hg_test
|
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.
|
2017-11-08 05:47:42 +03:00
|
|
|
class MoveTest(EdenHgTestCase):
|
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
|
|
|
repo.write_file("hello.txt", "hola")
|
|
|
|
repo.commit("Initial commit.\n")
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_move_file_without_modification(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("move", "hello.txt", "goodbye.txt")
|
|
|
|
self.assert_status({"goodbye.txt": "A", "hello.txt": "R"})
|
|
|
|
extended_status = self.hg("status", "--copies")
|
|
|
|
self.assertEqual(
|
|
|
|
dedent(
|
|
|
|
"""\
|
2017-08-25 00:14:56 +03:00
|
|
|
A goodbye.txt
|
|
|
|
hello.txt
|
|
|
|
R hello.txt
|
2018-05-10 07:33:49 +03:00
|
|
|
"""
|
|
|
|
),
|
|
|
|
extended_status,
|
|
|
|
)
|
|
|
|
self.assert_copy_map({"goodbye.txt": "hello.txt"})
|
|
|
|
self.assertFalse(os.path.exists(self.get_path("hello.txt")))
|
|
|
|
self.assertTrue(os.path.exists(self.get_path("goodbye.txt")))
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
self.repo.commit("Commit copied file.\n")
|
2017-08-25 00:14:56 +03:00
|
|
|
self.assert_status_empty()
|
|
|
|
self.assert_copy_map({})
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_move_file_then_revert_it(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("move", "hello.txt", "goodbye.txt")
|
|
|
|
self.assert_status({"goodbye.txt": "A", "hello.txt": "R"})
|
|
|
|
self.assert_copy_map({"goodbye.txt": "hello.txt"})
|
|
|
|
self.assertFalse(os.path.exists(self.get_path("hello.txt")))
|
|
|
|
self.assertTrue(os.path.exists(self.get_path("goodbye.txt")))
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("revert", "--no-backup", "--all")
|
|
|
|
self.assert_status({"goodbye.txt": "?"})
|
2017-08-25 00:14:56 +03:00
|
|
|
self.assert_copy_map({})
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertTrue(os.path.exists(self.get_path("hello.txt")))
|
|
|
|
self.assertTrue(os.path.exists(self.get_path("goodbye.txt")))
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("add", "goodbye.txt")
|
|
|
|
extended_status = self.hg("status", "--copies")
|
|
|
|
self.assertEqual(
|
|
|
|
dedent(
|
|
|
|
"""\
|
2017-08-25 00:14:56 +03:00
|
|
|
A goodbye.txt
|
2018-05-10 07:33:49 +03:00
|
|
|
"""
|
|
|
|
),
|
|
|
|
extended_status,
|
|
|
|
)
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_replace_after_move_file_then_revert_it(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("move", "hello.txt", "goodbye.txt")
|
|
|
|
self.assert_status({"goodbye.txt": "A", "hello.txt": "R"})
|
|
|
|
self.assert_copy_map({"goodbye.txt": "hello.txt"})
|
|
|
|
self.assertFalse(os.path.exists(self.get_path("hello.txt")))
|
|
|
|
self.assertTrue(os.path.exists(self.get_path("goodbye.txt")))
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
self.write_file("hello.txt", "different contents")
|
|
|
|
self.assert_status({"goodbye.txt": "A", "hello.txt": "R"})
|
|
|
|
self.hg("add", "hello.txt")
|
|
|
|
self.assert_status({"goodbye.txt": "A", "hello.txt": "M"})
|
|
|
|
self.assert_copy_map({"goodbye.txt": "hello.txt"})
|
|
|
|
extended_status = self.hg("status", "--copies")
|
|
|
|
self.assertEqual(
|
|
|
|
dedent(
|
|
|
|
"""\
|
2017-08-25 00:14:56 +03:00
|
|
|
M hello.txt
|
|
|
|
A goodbye.txt
|
|
|
|
hello.txt
|
2018-05-10 07:33:49 +03:00
|
|
|
"""
|
|
|
|
),
|
|
|
|
extended_status,
|
|
|
|
)
|
2017-08-25 00:14:56 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
self.hg("revert", "--no-backup", "--all")
|
|
|
|
self.assert_status({"goodbye.txt": "?"})
|
2017-08-25 00:14:56 +03:00
|
|
|
self.assert_copy_map({})
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertTrue(os.path.exists(self.get_path("hello.txt")))
|
|
|
|
self.assertTrue(os.path.exists(self.get_path("goodbye.txt")))
|