From 3fafe65f0ae99754c0b9683164e155bb25747505 Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Sat, 14 Nov 2026 08:36:39 +0100 Subject: [PATCH 1/5] ci: turn off Defender scanning on Windows The tests start many git processes and write many small files. Defender scans each one. --- .github/workflows/test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c3526cf..47b8ff13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,12 @@ jobs: # authorship) needs real history, not the default shallow, tagless # checkout. fetch-depth: 0 + # The tests start many git processes and write many small files. + # On Windows, Defender scans each one, which makes the tests slow. + - name: Turn off Defender scanning + if: runner.os == 'Windows' + shell: pwsh + run: Set-MpPreference -DisableRealtimeMonitoring $true - name: Install uv uses: astral-sh/setup-uv@v10.3.3 with: From 1fb03096dd0e072473a8d8eba73a3db463455e3a Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Sat, 14 Nov 2026 08:44:06 +0100 Subject: [PATCH 2/5] test: build the upstream repos once per session Each test copies them. It no longer builds them again. The fixtures also make fewer git calls. This makes the tests much faster on Windows, where each git call is slow. --- tests/conftest.py | 86 ++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6dc1c56d..e9a736f4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -158,15 +158,12 @@ def add_new_files(self, *files, cwd=None): file_path = Path(cwd) / file if cwd else Path(file) file_path.parent.mkdir(parents=True, exist_ok=True) file_path.write_text(f"new file {file}\n") - subprocess.run(['git', 'add', '--force', str(file)], cwd=cwd, check=True) - + subprocess.run(['git', 'add', '--force', '--', *map(str, files)], cwd=cwd, check=True) subprocess.run(['git', 'commit', '--quiet', '-m', f'add new file: {files[-1]}'], cwd=cwd, check=True) def remove_files(self, *files, cwd=None): """Remove files and commit""" - for file in files: - subprocess.run(['git', 'rm', file], cwd=cwd, check=True) - + subprocess.run(['git', 'rm', '--', *map(str, files)], cwd=cwd, check=True) subprocess.run(['git', 'commit', '--quiet', '-m', f'Removed file: {files[-1]}'], cwd=cwd, check=True) def modify_files(self, *files, text=None, cwd=None): @@ -176,8 +173,7 @@ def modify_files(self, *files, text=None, cwd=None): file_path = Path(cwd) / file if cwd else Path(file) with file_path.open('a') as f: f.write(f'{text}\n') - subprocess.run(['git', 'add', str(file)], cwd=cwd, check=True) - + subprocess.run(['git', 'add', '--', *map(str, files)], cwd=cwd, check=True) subprocess.run(['git', 'commit', '-m', f'modified file: {files[-1]}'], cwd=cwd, check=True) @@ -188,10 +184,9 @@ def modify_files(self, *files, text=None, cwd=None): def clone_repo(upstream: str, path: Path): path.parent.mkdir(parents=True, exist_ok=True) - subprocess.run(['git', 'clone', upstream, path], check=True, capture_output=True) name = path.name - subprocess.run(['git', 'config', 'user.name', f'{name.capitalize()}User'], cwd=path, check=True) - subprocess.run(['git', 'config', 'user.email', f'{name}@{name}'], cwd=path, check=True) + identity = ['-c', f'user.name={name.capitalize()}User', '-c', f'user.email={name}@{name}'] + subprocess.run(['git', 'clone', *identity, upstream, path], check=True, capture_output=True) def remove_tree(path: Path) -> None: @@ -224,8 +219,8 @@ def create_upstream_repo(repo_path: Path) -> Path: work_dir = repo_path.parent / (repo_path.name + ".tmp") work_dir.mkdir(exist_ok=True) subprocess.run(['git', 'init'], cwd=work_dir, check=True, capture_output=True) - subprocess.run(['git', 'config', 'user.name', 'Test'], cwd=work_dir, check=True, capture_output=True) - subprocess.run(['git', 'config', 'user.email', 'test@test'], cwd=work_dir, check=True, capture_output=True) + with (work_dir / '.git' / 'config').open('a') as f: + f.write('[user]\n\tname = Test\n\temail = test@test\n') return work_dir @@ -417,8 +412,42 @@ def git_exec_path(tmp_path_factory) -> Path | None: return shadow +def _isolate_git(home: Path, git_exec_path: Path | None, path_dirs: list[Path]) -> dict[str, str]: + """Write a global git config into home and return env vars that use only it""" + (home / '.gitconfig').write_text( + '[user]\n\tname = Test User\n\temail = test@example.com\n[init]\n\tdefaultBranch = master\n' + ) + env_vars = { + 'HOME': str(home), + 'GIT_CONFIG_GLOBAL': str(home / '.gitconfig'), + 'GIT_CONFIG_SYSTEM': os.devnull, + # Drops config injected through the caller's environment, such as safe.bareRepository. + 'GIT_CONFIG_COUNT': '0', + 'PATH': os.pathsep.join([*map(str, path_dirs), os.getenv('PATH', '')]), + } + if git_exec_path: + env_vars['GIT_EXEC_PATH'] = str(git_exec_path) + return env_vars + + +@pytest.fixture(scope='session') +def upstream_template(tmp_path_factory, git_exec_path) -> Path: + """The foo and bar upstreams, built once per session + + Each test gets a copy. Copying is much faster than building them again, + above all on Windows, where each git call is slow. + """ + template = tmp_path_factory.mktemp('upstream-template') + home = template / 'home' + home.mkdir() + with update_env(_isolate_git(home, git_exec_path, [])): + create_upstream_foo(template / 'upstream' / 'foo') + create_upstream_bar(template / 'upstream' / 'bar') + return template / 'upstream' + + @pytest.fixture -def env(tmp_path, git_exec_path): +def env(tmp_path, git_exec_path, upstream_template): """Setup isolated test environment with git repos""" root_dir = Path(__file__).parent.parent tmp_dir = Path(tmp_path) @@ -438,31 +467,12 @@ def env(tmp_path, git_exec_path): (shim_dir / 'python3').write_text(f'#!/bin/sh\nexec "{Path(sys.executable).as_posix()}" "$@"\n') path_dirs.insert(0, shim_dir) - # Set up isolated environment variables - env_vars = { - 'HOME': str(test_env.test_home), - 'GIT_CONFIG_GLOBAL': str(test_env.test_home / '.gitconfig'), - 'GIT_CONFIG_SYSTEM': os.devnull, - # Drops config injected through the caller's environment, such as safe.bareRepository. - 'GIT_CONFIG_COUNT': '0', - # bin/ holds the 'git-nested' launcher `git nested` dispatches to -- - # replaced by the directory of the frozen binary when testing that. - 'PATH': os.pathsep.join([*map(str, path_dirs), os.getenv('PATH', '')]), - } - if git_exec_path: - env_vars['GIT_EXEC_PATH'] = str(git_exec_path) - - with update_env(env_vars): - # Configure git - subprocess.run(['git', 'config', '--global', 'user.name', 'Test User'], check=True) - subprocess.run(['git', 'config', '--global', 'user.email', 'test@example.com'], check=True) - subprocess.run(['git', 'config', '--global', 'init.defaultBranch', 'master'], check=True) - - # Create test repositories. 'init' is deliberately absent -- it is - # built lazily by NestedTestEnvironment.clone_init, see there. - create_upstream_foo(test_env.upstream / 'foo') - create_upstream_bar(test_env.upstream / 'bar') - + # bin/ holds the 'git-nested' launcher `git nested` dispatches to -- + # replaced by the directory of the frozen binary when testing that. + with update_env(_isolate_git(test_env.test_home, git_exec_path, path_dirs)): + # 'init' is deliberately absent -- it is built lazily by + # NestedTestEnvironment.clone_init, see there. + shutil.copytree(upstream_template, test_env.upstream) yield test_env From 32b046927ab6daddeee374a63ddbd7a8e00b313c Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Sat, 14 Nov 2026 08:44:06 +0100 Subject: [PATCH 3/5] perf: make fewer git calls - Check ref names in Python instead of with git check-ref-format. - Ask for the git version only once per git binary. - Ask for --git-dir and --is-inside-work-tree in one call. - Ask for the worktree suffix only once per command. --- src/git_nested/checks.py | 6 ++-- src/git_nested/cli/setup.py | 2 +- src/git_nested/commands/clean.py | 2 +- src/git_nested/commands/clone.py | 4 +-- src/git_nested/commands/pull.py | 4 +-- src/git_nested/commands/status.py | 2 +- src/git_nested/content.py | 6 ++-- src/git_nested/git.py | 21 ++++++++++-- src/git_nested/refs.py | 17 ++++++---- tests/unit/test_helpers.py | 55 ++++++++++++++++++++++++++++--- tests/unit/test_repo_business.py | 16 +++------ 11 files changed, 98 insertions(+), 37 deletions(-) diff --git a/src/git_nested/checks.py b/src/git_nested/checks.py index 3320ad4f..625c4f1f 100644 --- a/src/git_nested/checks.py +++ b/src/git_nested/checks.py @@ -20,7 +20,7 @@ def check_repository(git: GitRunner, command: str, flags: Flags) -> tuple[Path | return None, None try: - git.run(['rev-parse', '--git-dir']) + git_dir, inside_work_tree = git.check_output(['rev-parse', '--git-dir', '--is-inside-work-tree']).splitlines() except GitNestedError: # A deliberate re-interpretation of git's own message, not an # incidental failure, so the chain is suppressed -- and since @@ -29,14 +29,14 @@ def check_repository(git: GitRunner, command: str, flags: Flags) -> tuple[Path | raise GitNestedError("not inside a git repository") from None # Per worktree of this repository, so they do not block each other. - git_tmp = Path(git.check_output(['rev-parse', '--git-dir'])) / 'tmp' + git_tmp = Path(git_dir) / 'tmp' # Not a nested branch. A detached HEAD is fine: commits go there, as with git commit. current_branch = git.check_output(['symbolic-ref', '--short', '--quiet', 'HEAD'], may_fail=True) if current_branch.startswith('nested/'): raise GitNestedError(f"can't {command} while the nested branch {current_branch} is checked out") - if git.check_output(['rev-parse', '--is-inside-work-tree'], may_fail=True) != 'true': + if inside_work_tree != 'true': raise GitNestedError("not inside a git working tree") if _needs_clean_worktree(command, flags): diff --git a/src/git_nested/cli/setup.py b/src/git_nested/cli/setup.py index 6fe12a16..17293f88 100644 --- a/src/git_nested/cli/setup.py +++ b/src/git_nested/cli/setup.py @@ -61,7 +61,7 @@ def setup_command( tuple: (subdir, gitnested, subref, config) """ subdir = resolve_subdir(subdir) - subref = refs.sanitize_subref(git, subdir.as_posix()) + subref = refs.sanitize_subref(subdir.as_posix()) gitnested = resolve_gitnested_file(subdir) if not flags.force: diff --git a/src/git_nested/commands/clean.py b/src/git_nested/commands/clean.py index 68206271..f85245a2 100644 --- a/src/git_nested/commands/clean.py +++ b/src/git_nested/commands/clean.py @@ -12,7 +12,7 @@ def do_clean(git: GitRunner, flags: Flags, subdir: Path, git_tmp: Path) -> list[str]: """Clean nested branches and refs.""" - subref = refs.sanitize_subref(git, subdir.as_posix()) + subref = refs.sanitize_subref(subdir.as_posix()) items = _delete_branch(git, refs.nested_branch(git, subref), git_tmp) refs.record_nested_branch(git, subref, None) if flags.force: diff --git a/src/git_nested/commands/clone.py b/src/git_nested/commands/clone.py index 5fa5f9a3..bdab3c1d 100644 --- a/src/git_nested/commands/clone.py +++ b/src/git_nested/commands/clone.py @@ -139,7 +139,7 @@ def _adopt_existing_subdir( git, config, upstream_commit, upstream_commit, subdir, 'clone' ) content.commit_gitnested_update(git, flags, subdir, msg) - refs.create_nested_ref(git, refs.sanitize_subref(git, subdir.as_posix()), 'commit', upstream_commit) + refs.create_nested_ref(git, refs.sanitize_subref(subdir.as_posix()), 'commit', upstream_commit) def _clone_into( @@ -192,7 +192,7 @@ def nest_submodules(git: GitRunner, flags: Flags, config: NestedConfig, subdir: are skipped. """ in_index = dict(submodules.gitlinks(git, subdir)) - for relative, pinned in sorted(submodules.gitlinks_at(git, content.nested_tree(git, config, subdir)).items()): + for relative, pinned in sorted(submodules.gitlinks_at(git, content.nested_tree(config, subdir)).items()): path = f'{subdir.as_posix()}/{relative}' if (Path(path) / GITNESTED_FILENAME).is_file() or ((config.filter or config.exclude) and path not in in_index): continue diff --git a/src/git_nested/commands/pull.py b/src/git_nested/commands/pull.py index cd8bf656..7cec1d76 100644 --- a/src/git_nested/commands/pull.py +++ b/src/git_nested/commands/pull.py @@ -165,7 +165,7 @@ def _rewrite_history_with_prefix( git: GitRunner, flags: Flags, nested_commit_ref: str, subdir: Path, git_tmp: Path, subref: str ) -> str: """Replay `nested_commit_ref` as commits whose trees live under `subdir/`.""" - scratch = git_tmp / '.pull-no-squash' / f'{refs.sanitize_subref(git, subref)}-{uuid4().hex}' + scratch = git_tmp / '.pull-no-squash' / f'{refs.sanitize_subref(subref)}-{uuid4().hex}' scratch.mkdir(parents=True, exist_ok=True) index_env = {**os.environ, 'GIT_INDEX_FILE': str(scratch / 'index')} rewritten: dict[str, str] = {} @@ -334,7 +334,7 @@ def follow_inner(ctx: CommandContext, config: NestedConfig, subdir: Path) -> Non If one stops on conflicts, a new pull of subdir does the rest. """ git = ctx.git - for relative, pin in sorted(submodules.gitlinks_at(git, content.nested_tree(git, config, subdir)).items()): + for relative, pin in sorted(submodules.gitlinks_at(git, content.nested_tree(config, subdir)).items()): path = subdir / relative if not (path / GITNESTED_FILENAME).is_file(): continue diff --git a/src/git_nested/commands/status.py b/src/git_nested/commands/status.py index 2bd15846..9dccf598 100644 --- a/src/git_nested/commands/status.py +++ b/src/git_nested/commands/status.py @@ -36,7 +36,7 @@ def get_status(git: GitRunner, flags: Flags) -> str: def _status_for_subdir(git: GitRunner, flags: Flags, subdir: Path) -> str: """The status report of one nested subdir.""" - subref = refs.sanitize_subref(git, subdir.as_posix()) + subref = refs.sanitize_subref(subdir.as_posix()) gitnested = subdir / GITNESTED_FILENAME if not gitnested.is_file(): return f"'{subdir.as_posix()}' is not a nested repository\n" diff --git a/src/git_nested/content.py b/src/git_nested/content.py index 30867384..30d1b79e 100644 --- a/src/git_nested/content.py +++ b/src/git_nested/content.py @@ -109,7 +109,7 @@ def commit_nested_branch( commit_gitnested_update(git, flags, subdir, msg) worktree.remove_worktree(git, subdir_worktree) - refs.create_nested_ref(git, refs.sanitize_subref(git, subdir.as_posix()), 'commit', nested_commit_ref) + refs.create_nested_ref(git, refs.sanitize_subref(subdir.as_posix()), 'commit', nested_commit_ref) def place_with_patches(git: GitRunner, config: NestedConfig, subdir: Path, nested_commit_ref: str) -> list[str] | None: @@ -157,9 +157,9 @@ def _drop_gitlink(git: GitRunner, path: Path) -> None: path.rmdir() -def nested_tree(git: GitRunner, config: NestedConfig, subdir: Path) -> str: +def nested_tree(config: NestedConfig, subdir: Path) -> str: """The tree that subdir got its content from in the last clone, pull or commit.""" - tree = f'refs/nested/{refs.sanitize_subref(git, subdir.as_posix())}/commit' + tree = f'refs/nested/{refs.sanitize_subref(subdir.as_posix())}/commit' return f'{tree}:{config.path}' if config.path else tree diff --git a/src/git_nested/git.py b/src/git_nested/git.py index fd806ba0..3d7e3015 100644 --- a/src/git_nested/git.py +++ b/src/git_nested/git.py @@ -13,6 +13,10 @@ from .constants import REQUIRED_GIT_VERSION from .errors import GitNestedError +# The version of each git binary, so it is asked only once per process. +# The test suite runs many commands in one process. +_VERSIONS: dict[str, str] = {} + class GitRunner: """Simplified git command execution.""" @@ -56,6 +60,17 @@ def check_output(self, args: Sequence[str | Path], may_fail: bool = False, **kwa result = self.run(args=args, may_fail=may_fail, **kwargs) return result.stdout.strip() + def cached_output(self, args: Sequence[str]) -> str: + """check_output, but git is asked only once per directory. + + Only for answers that do not change while a command runs. + """ + cache: dict[tuple[Path, tuple[str, ...]], str] = self.__dict__.setdefault('_cache', {}) + key = (Path.cwd(), tuple(args)) + if key not in cache: + cache[key] = self.check_output(args) + return cache[key] + def is_tracked(self, path: Path) -> bool: """Check if given path is tracked by git. @@ -81,15 +96,17 @@ def commit_in_rev_list(self, commit: str, list_head: str) -> bool: def check(self) -> None: """Check that environment is suitable.""" - if not shutil.which('git'): + path = shutil.which('git') + if not path: raise GitNestedError("git is not on PATH") - version = self.get_version() + version = _VERSIONS.get(path) or self.get_version() def version_tuple(v: str) -> tuple[int, ...]: return tuple(map(int, (v.split(".")))) if version_tuple(version) < version_tuple(REQUIRED_GIT_VERSION): raise GitNestedError(f"git {REQUIRED_GIT_VERSION} or newer is required, but this is {version}") + _VERSIONS[path] = version def get_version(self) -> str: """Return the installed git version string (e.g. '2.43.0').""" diff --git a/src/git_nested/refs.py b/src/git_nested/refs.py index ac2afcee..bcc23780 100644 --- a/src/git_nested/refs.py +++ b/src/git_nested/refs.py @@ -2,6 +2,7 @@ from __future__ import annotations +import re from pathlib import Path from urllib.parse import quote @@ -26,7 +27,7 @@ def worktree_suffix(git: GitRunner) -> str: So the worktrees of this repository each get their own nested branches. """ - git_dir, common_dir = git.check_output(['rev-parse', '--git-dir', '--git-common-dir']).splitlines() + git_dir, common_dir = git.cached_output(['rev-parse', '--git-dir', '--git-common-dir']).splitlines() if Path(git_dir).resolve() == Path(common_dir).resolve(): return '' return f'@{Path(git_dir).name}' @@ -86,14 +87,18 @@ def guess_subdir(remote: str) -> str: return Path(remote).name.removesuffix('.git') -def _is_valid_ref(git: GitRunner, ref: str) -> bool: +# The rules of `git check-ref-format`, checked here to save a git call +_BAD_REF = re.compile(r'[\x00-\x20\x7f~^:?*\[\\]|\.\.|@\{|//|^/|/$|\.$|(^|/)\.|\.lock(/|$)') + + +def _is_valid_ref(ref: str) -> bool: """Check whether ref is already a valid git ref name (as a nested/ subref).""" - return git.run(['check-ref-format', f'nested/{ref}'], may_fail=True).returncode == 0 + return not _BAD_REF.search(f'nested/{ref}') -def sanitize_subref(git: GitRunner, ref: str) -> str: +def sanitize_subref(ref: str) -> str: """Sanitize subref to be a valid git ref.""" - if _is_valid_ref(git, ref): + if _is_valid_ref(ref): return ref sanitized = quote(ref, safe='/') @@ -106,6 +111,6 @@ def sanitize_subref(git: GitRunner, ref: str) -> str: sanitized = sanitized.removesuffix('.lock') + '_lock' sanitized = sanitized.removesuffix('.') - if not _is_valid_ref(git, sanitized): + if not _is_valid_ref(sanitized): raise GitNestedError(f"can't derive a git ref name from {ref}") return sanitized diff --git a/tests/unit/test_helpers.py b/tests/unit/test_helpers.py index d662cc92..7eade055 100644 --- a/tests/unit/test_helpers.py +++ b/tests/unit/test_helpers.py @@ -88,6 +88,7 @@ def test_git_runner_raises_when_git_not_on_path(monkeypatch): def test_git_runner_raises_when_git_version_too_old(monkeypatch): monkeypatch.setattr(GitRunner, "get_version", lambda self: "1.0.0") + monkeypatch.setattr(git_module, "_VERSIONS", {}) git = GitRunner() with pytest.raises(GitNestedError, match="or newer is required"): git.check() @@ -124,9 +125,9 @@ def test_sanitize_subref_raises_when_unsanitizable(monkeypatch): """Force the 'even sanitized, still not a valid ref' guard for an input we can't otherwise construct""" # Patch the definition in git_nested.refs, not any re-export of it: only # the definition is what sanitize_subref's own call resolves through. - monkeypatch.setattr(refs, "_is_valid_ref", lambda git, ref: False) + monkeypatch.setattr(refs, "_is_valid_ref", lambda ref: False) with pytest.raises(GitNestedError, match="can't derive a git ref name"): - refs.sanitize_subref(git=NO_GIT, ref="whatever") + refs.sanitize_subref(ref="whatever") def test_sanitize_subref_drops_a_trailing_dot(): @@ -135,8 +136,54 @@ def test_sanitize_subref_drops_a_trailing_dot(): The e2e encoding tests reach this too, but with directory names Windows cannot create, so there it is only covered here. """ - git = FakeGit().respond('check-ref-format', 'nested/trailing-dots...', returncode=1).respond('check-ref-format') - assert refs.sanitize_subref(git, 'trailing-dots...') == 'trailing-dots_' + assert refs.sanitize_subref('trailing-dots...') == 'trailing-dots_' + + +# Checked against `git check-ref-format nested/` +@pytest.mark.parametrize( + ('ref', 'valid'), + [ + ('lib', True), + ('lib/inner', True), + ('lib-1.2_x', True), + ('äöü', True), + ('a@b', True), + ('a.b', True), + ('', False), + ('a b', False), + ('a\tb', False), + ('a\x7fb', False), + ('a~b', False), + ('a^b', False), + ('a:b', False), + ('a?b', False), + ('a*b', False), + ('a[b', False), + ('a\\b', False), + ('a..b', False), + ('a@{b', False), + ('a//b', False), + ('/a', False), + ('a/', False), + ('a.', False), + ('.a', False), + ('a/.b', False), + ('a.lock', False), + ('a.lock/b', False), + ('a.locks', True), + ], +) +def test_is_valid_ref_follows_git_rules(ref, valid): + assert refs._is_valid_ref(ref) is valid + + +def test_cached_output_asks_git_once_per_directory(tmp_path, monkeypatch): + git = FakeGit().respond('rev-parse', stdout='.git') + assert git.cached_output(['rev-parse', '--git-dir']) == '.git' + assert git.cached_output(['rev-parse', '--git-dir']) == '.git' + monkeypatch.chdir(tmp_path) + git.cached_output(['rev-parse', '--git-dir']) + assert git.calls.count(('rev-parse', '--git-dir')) == 2 # ============================================================================ diff --git a/tests/unit/test_repo_business.py b/tests/unit/test_repo_business.py index a1de8f9e..b5d76145 100644 --- a/tests/unit/test_repo_business.py +++ b/tests/unit/test_repo_business.py @@ -414,12 +414,7 @@ def test_classify_raises_on_invalid_regex(): def test_check_repository_raises_on_nested_branch_checked_out(): - git = ( - FakeGit() - .respond('rev-parse', '--git-dir') - .respond('rev-parse', '--git-common-dir', stdout='.git') - .respond('symbolic-ref', stdout='nested/sub') - ) + git = FakeGit().respond('rev-parse', '--git-dir', stdout='.git\ntrue').respond('symbolic-ref', stdout='nested/sub') flags = Flags() with pytest.raises(GitNestedError, match="while the nested branch"): checks.check_repository(git, 'pull', flags) @@ -428,9 +423,8 @@ def test_check_repository_raises_on_nested_branch_checked_out(): def test_check_repository_skips_clean_tree_for_branch(): git = ( FakeGit() - .respond('rev-parse', '--git-dir', stdout='.git') + .respond('rev-parse', '--git-dir', stdout='.git\ntrue') .respond('symbolic-ref', returncode=1) - .respond('rev-parse', '--is-inside-work-tree', stdout='true') .respond('rev-parse', 'HEAD', stdout='deadbeef') ) assert checks.check_repository(git, 'branch', Flags()) == (Path('.git/tmp'), 'deadbeef') @@ -440,9 +434,8 @@ def test_check_repository_skips_clean_tree_for_branch(): def test_check_repository_checks_clean_tree_for_push_commit(): git = ( FakeGit() - .respond('rev-parse', '--git-dir', stdout='.git') + .respond('rev-parse', '--git-dir', stdout='.git\ntrue') .respond('symbolic-ref', returncode=1) - .respond('rev-parse', '--is-inside-work-tree', stdout='true') .respond('update-index', returncode=0) .respond('diff-files', '--quiet', '--ignore-submodules', returncode=1) ) @@ -454,9 +447,8 @@ def test_check_repository_checks_clean_tree_for_push_commit(): def test_check_repository_returns_no_head_in_empty_repo(): git = ( FakeGit() - .respond('rev-parse', '--git-dir', stdout='.git') + .respond('rev-parse', '--git-dir', stdout='.git\ntrue') .respond('symbolic-ref', stdout='main') - .respond('rev-parse', '--is-inside-work-tree', stdout='true') .respond('update-index') .respond('diff-files', '--quiet', '--ignore-submodules') .respond('rev-list', 'HEAD', '-1', returncode=1) From 4d9d47aea7ae1c5bb22dfc72ec8023556e73024e Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Sat, 14 Nov 2026 08:44:06 +0100 Subject: [PATCH 4/5] ci: test only the oldest and newest Python on PRs main still tests all Python versions. --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47b8ff13..88edb37a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,7 +77,8 @@ jobs: fail-fast: false matrix: os: [ubuntu-26.04, macos-latest, windows-latest] - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + # A PR runs only the oldest and newest Python. main runs all of them. + python-version: ${{ fromJSON(github.event_name == 'pull_request' && '["3.10", "3.14"]' || '["3.10", "3.11", "3.12", "3.13", "3.14"]') }} steps: - name: Checkout code From 1994aa59484d59ef15a06418fda06478fb35d4b4 Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Sat, 14 Nov 2026 08:44:55 +0100 Subject: [PATCH 5/5] ci: put TEMP on a Dev Drive on Windows The test repos in tmp_path then live on a fast ReFS drive. --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88edb37a..6c2e8d98 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,6 +94,21 @@ jobs: if: runner.os == 'Windows' shell: pwsh run: Set-MpPreference -DisableRealtimeMonitoring $true + # A Dev Drive is a fast ReFS drive. TEMP points there, so the test + # repos in tmp_path live on it. + - name: Set up Dev Drive + if: runner.os == 'Windows' + uses: samypr100/setup-dev-drive@v4.1.0 + with: + drive-size: 8GB + drive-path: ${{ runner.temp }}/dev_drive.vhdx + trusted-dev-drive: true + env-mapping: | + TEMP,{{ DEV_DRIVE }}/tmp + TMP,{{ DEV_DRIVE }}/tmp + - name: Create temp dir on Dev Drive + if: runner.os == 'Windows' + run: mkdir -p "$TEMP" && echo "TEMP=$TEMP" - name: Install uv uses: astral-sh/setup-uv@v10.3.3 with: