diff --git a/python/mozversioncontrol/test/conftest.py b/python/mozversioncontrol/test/conftest.py index 86c3c0e80fab..ee008f1bc206 100644 --- a/python/mozversioncontrol/test/conftest.py +++ b/python/mozversioncontrol/test/conftest.py @@ -3,10 +3,8 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import os -import platform import shutil import subprocess -import tempfile from pathlib import Path from typing import List @@ -55,12 +53,13 @@ SETUP = { git config user.email "" git add * git commit -am "Initial commit" - jj git init --colocate - jj config set --repo user.name "Testing McTesterson" - jj config set --repo user.email "test@example.org" - jj describe --reset-author --no-edit """, """ + # Pass in user name/email via env vars because the initial commit + # will use them before we have a chance to configure them. + JJ_USER="Testing McTesterson" JJ_EMAIL="test@example.org" jj git init --colocate + jj config set --repo user.name "Testing McTesterson" + jj config set --repo user.email "test@example.org" jj git remote add upstream ../remoterepo jj git fetch --remote upstream jj bookmark track master@upstream @@ -97,27 +96,17 @@ def shell(cmd, working_dir): @pytest.fixture(params=["git", "hg", "jj", "src"]) -def repo(request): +def repo(tmpdir, request): if request.param == "jj": - if os.getenv("MOZ_AUTOMATION") == 1: - fetches_dir = os.environ.get("MOZ_FETCHES_DIR", "") - jj_dir = Path(fetches_dir) / "jj" - if jj_dir.is_dir(): - os.environ["PATH"] = os.pathsep.join([str(jj_dir), os.environ["PATH"]]) - if platform.system() == "Darwin": - pytest.skip( - "jj tests disabled for MacOS CI due to incompatible git on workers" - ) if os.getenv("MOZ_AVOID_JJ_VCS") not in (None, "0", ""): pytest.skip("jj support disabled") try: subprocess.call(["jj", "--version"], stdout=subprocess.DEVNULL) except OSError: pytest.skip("jj unavailable") + + tmpdir = Path(tmpdir) vcs = request.param - # Use tempfile since pytest's tempdir is too long for jj on Windows - td = tempfile.TemporaryDirectory(prefix=f"{vcs}-repo") - tmpdir = Path(td.name) steps = SETUP[vcs] if hasattr(request.module, "STEPS"): diff --git a/python/mozversioncontrol/test/test_commit.py b/python/mozversioncontrol/test/test_commit.py index a9e245652449..cb5504b9e462 100644 --- a/python/mozversioncontrol/test/test_commit.py +++ b/python/mozversioncontrol/test/test_commit.py @@ -2,7 +2,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -import re from datetime import datetime from pathlib import Path @@ -27,7 +26,7 @@ STEPS = { ], "jj": [ """ - jj describe -m "Ignore file for testing" + jj describe -m 'Ignore file for testing' echo foo > .gitignore jj new """, @@ -107,32 +106,9 @@ def test_commit(repo): # Verify only the intended file was added to the commit patch = vcs._run(*patch_cmd) - - def find_diff_marker(patch: str, filename: str): - patterns = [ - rf"^diff --git a/{re.escape(filename)} b/{re.escape(filename)}$", - rf"^Modified regular file {re.escape(filename)}:$", - ] - - matches = [ - line - for line in patch.splitlines() - if any(re.fullmatch(p, line) for p in patterns) - ] - - assert matches, f"No diff marker found for '{filename}'" - assert ( - len(matches) == 1 - ), f"More than one diff marker for '{filename}': {matches}" - - return matches[0] - - marker = find_diff_marker(patch, "bar") - - assert marker in [ - "diff --git a/bar b/bar", - "Modified regular file bar:", - ] + diffs = [line for line in patch.splitlines() if "diff --git" in line] + assert len(diffs) == 1 + assert diffs[0] == "diff --git a/bar b/bar" if __name__ == "__main__": diff --git a/python/mozversioncontrol/test/test_get_commit_patches.py b/python/mozversioncontrol/test/test_get_commit_patches.py index 4b514226d1aa..35b77b7f7c67 100644 --- a/python/mozversioncontrol/test/test_get_commit_patches.py +++ b/python/mozversioncontrol/test/test_get_commit_patches.py @@ -35,11 +35,10 @@ STEPS = { jj new -m "FIRST PATCH" echo bar >> bar """, - # snapshot, since bug 1962245 suppresses automatic ones """ jj new -m "SECOND PATCH" printf "baz\\r\\nqux" > baz - jj log -n0 + jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones """, ], } diff --git a/python/mozversioncontrol/test/test_get_commits.py b/python/mozversioncontrol/test/test_get_commits.py index 54a315965356..5f3a0bd37ee9 100644 --- a/python/mozversioncontrol/test/test_get_commits.py +++ b/python/mozversioncontrol/test/test_get_commits.py @@ -27,13 +27,12 @@ STEPS = { """ ], "jj": [ - # snapshot, since mach's jj integration avoids doing this automatically """ jj new -m "commit 1" echo bar >> bar jj commit -m "commit 2" echo baz > baz - jj log -n0 + jj log -n0 # snapshot, since mach's jj integration avoids doing this automatically """ ], } diff --git a/python/mozversioncontrol/test/test_workdir_outgoing.py b/python/mozversioncontrol/test/test_workdir_outgoing.py index 0ebcc91b3400..0f620b1db71e 100644 --- a/python/mozversioncontrol/test/test_workdir_outgoing.py +++ b/python/mozversioncontrol/test/test_workdir_outgoing.py @@ -48,12 +48,11 @@ STEPS = { """, ], "jj": [ - # snapshot, since bug 1962245 suppresses automatic ones """ echo "bar" >> bar echo "baz" > baz rm foo - jj log -n0 + jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones """, """ jj commit -m "Remove foo; modify bar; add baz" @@ -61,7 +60,7 @@ STEPS = { """ echo ooka >> baz echo newborn > baby - jj log -n0 + jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones """, """ jj describe -m "Modify baz; add baby"