Files
AnyPS5/tools/tests/test_main_sync_renames.py
T
AdriàandClaude Sonnet 5.5 e98780eb82 fix(main): derive the detection-disabled rename expectation from the running git
#11805 added test_main_sync_renames; main's push build 41455131775 failed its two detection-disabled cases on the runner's git 2.43, whose merge-tree ignores diff.renames/merge.renames and always detects the rename, so no conflict is reported. The tests now probe merge-tree on the fixture and expect a conflict only when the running git reports one; with detection enabled they still require a clean merge.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-02 16:20:25 +01:00

78 lines
3.6 KiB
Python

import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import check_main_sync
class RenamedPathsTests(unittest.TestCase):
def check_rename(self, side, setting):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
environment = {**os.environ, "GIT_AUTHOR_NAME": "Fixture", "GIT_AUTHOR_EMAIL": "[email protected]",
"GIT_COMMITTER_NAME": "Fixture", "GIT_COMMITTER_EMAIL": "[email protected]"}
def git(*args):
return subprocess.run(["git", "-C", str(root), "-c", "commit.gpgSign=false", *args],
capture_output=True, text=True, encoding="utf-8", check=True, env=environment).stdout.strip()
original, renamed = "before \u00e9.txt", "after \u6e2c.txt"
git("init", "-q", "-b", "main")
git("config", "diff.renames", setting)
text = "\n".join(f"line {index}" for index in range(50)) + "\n"
(root / original).write_text(text, encoding="utf-8")
git("add", ".")
git("commit", "-qm", "test: common source")
git("checkout", "-qb", "feature")
if side == "feature":
git("mv", original, renamed)
else:
(root / original).write_text(text.replace("line 0\n", "changed\n"), encoding="utf-8")
git("add", "-A")
git("commit", "-qm", "test: feature")
git("checkout", "-q", "main")
if side == "main":
git("mv", original, renamed)
else:
(root / original).write_text(text.replace("line 0\n", "changed\n"), encoding="utf-8")
git("add", "-A")
git("commit", "-qm", "fix(test): main change (#123)")
probe = subprocess.run(["git", "-C", str(root), "merge-tree", "--write-tree", "main", "feature"],
capture_output=True, text=True, encoding="utf-8", env=environment)
conflicting = probe.returncode == 1
if setting == "true":
self.assertFalse(conflicting)
data = check_main_sync.report(root, "main", "feature")
self.assertEqual(data["shared"], [original])
self.assertEqual(set(data["pulls"]), {123})
self.assertEqual(data["conflicts"], [original] if conflicting else [])
if setting == "true":
tree = git("merge-tree", "--write-tree", "main", "feature").splitlines()[0]
self.assertIn("changed", git("show", f"{tree}:{renamed}"))
result = subprocess.run([sys.executable, str(Path(check_main_sync.__file__)), "--repo", str(root),
"--base", "main", "--head", "feature"], capture_output=True, text=True, encoding="utf-8",
env={**environment, "PYTHONIOENCODING": "utf-8"})
self.assertEqual(result.returncode, 1 if conflicting else 0, result.stderr)
self.assertIn(original, result.stdout)
self.assertIn("#123", result.stdout)
def test_feature_rename_keeps_the_original_path(self):
self.check_rename("feature", "true")
def test_feature_rename_with_detection_disabled(self):
self.check_rename("feature", "false")
def test_main_rename_keeps_the_original_path(self):
self.check_rename("main", "true")
def test_main_rename_with_detection_disabled(self):
self.check_rename("main", "false")
if __name__ == "__main__":
unittest.main()