Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import shutil
import sys
import tempfile
from typing import Optional
from pathlib import Path
from textwrap import dedent
from typing import Iterator, Optional

import pytest

Expand Down Expand Up @@ -68,3 +70,33 @@ def testrepo2(HOME, tmpdir):
# homely-add the repo
from homely._test.system import TempRepo
yield _get_test_repo(TempRepo(tmpdir, 'cool-testrepo-2'))


@pytest.fixture(autouse=True, scope='session')
def force_git_config() -> Iterator[None]:
with tempfile.TemporaryDirectory() as tmpdir:
# force git commands to use a gitconfig that will:
# A) provide a user.name/user.email for committing
# B) allow the "file" protocol so that submodules can be cloned from
# filesystem paths instead of URLs
# C) prevent anything in the host's user git config (like
# core.hooksPath) from slowing down or interfereing with tests.
gitconfigpath = Path(tmpdir) / 'gitconfig'
gitconfigpath.write_text(
dedent(
'''
[protocol.file]
allow = always
[user]
name = "John Smith"
email = "john@example.com"
'''
)
)
m = pytest.MonkeyPatch()
try:
# prevent reading any local git config during the tests
m.setenv('GIT_CONFIG_GLOBAL', str(gitconfigpath))
yield
finally:
m.undo()
9 changes: 2 additions & 7 deletions test/unit/homely/_vcs/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@

from homely._test import contents

GIT = [
'git',
'-c',
'user.name=John Smith',
'-c',
'user.email=john@example.com',
]
# TODO: get rid of this thing
GIT: list[str | os.PathLike] = ['git']


def makegitrepo(tmpdir, name):
Expand Down
Loading