Skip to content

Commit 96acc22

Browse files
authored
Merge pull request #1745 from EliahKagan/ci-windows
Test native Windows on CI
2 parents a2644da + e00fffc commit 96acc22

12 files changed

+350
-78
lines changed

.github/workflows/cygwin-test.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ jobs:
7070
command -v git python
7171
git version
7272
python --version
73-
python -c 'import sys; print(sys.platform)'
74-
python -c 'import os; print(os.name)'
75-
python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly.
73+
python -c 'import os, sys; print(f"sys.platform={sys.platform!r}, os.name={os.name!r}")'
7674
7775
- name: Test with pytest
7876
run: |

.github/workflows/pythonpackage.yml

+20-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ permissions:
1010

1111
jobs:
1212
build:
13-
runs-on: ubuntu-latest
14-
1513
strategy:
1614
fail-fast: false
1715
matrix:
16+
os: ["ubuntu-latest", "windows-latest"]
1817
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
1918
include:
2019
- experimental: false
2120

21+
runs-on: ${{ matrix.os }}
22+
2223
defaults:
2324
run:
24-
shell: /bin/bash --noprofile --norc -exo pipefail {0}
25+
shell: bash --noprofile --norc -exo pipefail {0}
2526

2627
steps:
2728
- uses: actions/checkout@v4
@@ -34,6 +35,12 @@ jobs:
3435
python-version: ${{ matrix.python-version }}
3536
allow-prereleases: ${{ matrix.experimental }}
3637

38+
- name: Set up WSL (Windows)
39+
if: startsWith(matrix.os, 'windows')
40+
uses: Vampire/[email protected]
41+
with:
42+
distribution: Debian
43+
3744
- name: Prepare this repo for tests
3845
run: |
3946
./init-tests-after-clone.sh
@@ -61,9 +68,16 @@ jobs:
6168
command -v git python
6269
git version
6370
python --version
64-
python -c 'import sys; print(sys.platform)'
65-
python -c 'import os; print(os.name)'
66-
python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly.
71+
python -c 'import os, sys; print(f"sys.platform={sys.platform!r}, os.name={os.name!r}")'
72+
73+
# For debugging hook tests on native Windows systems that may have WSL.
74+
- name: Show bash.exe candidates (Windows)
75+
if: startsWith(matrix.os, 'windows')
76+
run: |
77+
set +e
78+
bash.exe -c 'printenv WSL_DISTRO_NAME; uname -a'
79+
python -c 'import subprocess; subprocess.run(["bash.exe", "-c", "printenv WSL_DISTRO_NAME; uname -a"])'
80+
continue-on-error: true
6781

6882
- name: Check types with mypy
6983
run: |

test-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pytest-cov
99
pytest-instafail
1010
pytest-mock
1111
pytest-sugar
12+
sumtypes

test/test_config.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
import glob
77
import io
88
import os
9+
import os.path as osp
910
from unittest import mock
1011

12+
import pytest
13+
1114
from git import GitConfigParser
1215
from git.config import _OMD, cp
13-
from test.lib import (
14-
TestCase,
15-
fixture_path,
16-
SkipTest,
17-
)
18-
from test.lib import with_rw_directory
19-
20-
import os.path as osp
2116
from git.util import rmfile
17+
from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory
2218

2319

2420
_tc_lock_fpaths = osp.join(osp.dirname(__file__), "fixtures/*.lock")
@@ -239,6 +235,11 @@ def check_test_value(cr, value):
239235
with GitConfigParser(fpa, read_only=True) as cr:
240236
check_test_value(cr, tv)
241237

238+
@pytest.mark.xfail(
239+
os.name == "nt",
240+
reason='Second config._has_includes() assertion fails (for "config is included if path is matching git_dir")',
241+
raises=AssertionError,
242+
)
242243
@with_rw_directory
243244
def test_conditional_includes_from_git_dir(self, rw_dir):
244245
# Initiate repository path.

test/test_diff.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,17 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6-
import ddt
6+
import os
7+
import os.path as osp
78
import shutil
89
import tempfile
9-
from git import (
10-
Repo,
11-
GitCommandError,
12-
Diff,
13-
DiffIndex,
14-
NULL_TREE,
15-
Submodule,
16-
)
17-
from git.cmd import Git
18-
from test.lib import (
19-
TestBase,
20-
StringProcessAdapter,
21-
fixture,
22-
)
23-
from test.lib import with_rw_directory
2410

25-
import os.path as osp
11+
import ddt
12+
import pytest
13+
14+
from git import NULL_TREE, Diff, DiffIndex, GitCommandError, Repo, Submodule
15+
from git.cmd import Git
16+
from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory
2617

2718

2819
def to_raw(input):
@@ -318,6 +309,11 @@ def test_diff_with_spaces(self):
318309
self.assertIsNone(diff_index[0].a_path, repr(diff_index[0].a_path))
319310
self.assertEqual(diff_index[0].b_path, "file with spaces", repr(diff_index[0].b_path))
320311

312+
@pytest.mark.xfail(
313+
os.name == "nt",
314+
reason='"Access is denied" when tearDown calls shutil.rmtree',
315+
raises=PermissionError,
316+
)
321317
def test_diff_submodule(self):
322318
"""Test that diff is able to correctly diff commits that cover submodule changes"""
323319
# Init a temp git repo that will be referenced as a submodule.

test/test_docs.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
import pytest
1010

11+
from git.exc import GitCommandError
1112
from test.lib import TestBase
1213
from test.lib.helper import with_rw_directory
1314

14-
import os.path
15-
1615

1716
class Tutorials(TestBase):
1817
def tearDown(self):
@@ -207,6 +206,14 @@ def update(self, op_code, cur_count, max_count=None, message=""):
207206
assert sm.module_exists() # The submodule's working tree was checked out by update.
208207
# ![14-test_init_repo_object]
209208

209+
@pytest.mark.xfail(
210+
os.name == "nt",
211+
reason=(
212+
"IndexFile.from_tree is broken on Windows (related to NamedTemporaryFile), see #1630.\n"
213+
"'git read-tree --index-output=...' fails with 'fatal: unable to write new index file'."
214+
),
215+
raises=GitCommandError,
216+
)
210217
@with_rw_directory
211218
def test_references_and_objects(self, rw_dir):
212219
# [1-test_references_and_objects]

test/test_fun.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
from io import BytesIO
55
from stat import S_IFDIR, S_IFREG, S_IFLNK, S_IXUSR
6-
from os import stat
6+
import os
77
import os.path as osp
88

9+
import pytest
10+
911
from git import Git
12+
from git.exc import GitCommandError
1013
from git.index import IndexFile
1114
from git.index.fun import (
1215
aggressive_tree_merge,
@@ -34,6 +37,14 @@ def _assert_index_entries(self, entries, trees):
3437
assert (entry.path, entry.stage) in index.entries
3538
# END assert entry matches fully
3639

40+
@pytest.mark.xfail(
41+
os.name == "nt",
42+
reason=(
43+
"IndexFile.from_tree is broken on Windows (related to NamedTemporaryFile), see #1630.\n"
44+
"'git read-tree --index-output=...' fails with 'fatal: unable to write new index file'."
45+
),
46+
raises=GitCommandError,
47+
)
3748
def test_aggressive_tree_merge(self):
3849
# Head tree with additions, removals and modification compared to its predecessor.
3950
odb = self.rorepo.odb
@@ -291,12 +302,12 @@ def test_linked_worktree_traversal(self, rw_dir):
291302
rw_master.git.worktree("add", worktree_path, branch.name)
292303

293304
dotgit = osp.join(worktree_path, ".git")
294-
statbuf = stat(dotgit)
305+
statbuf = os.stat(dotgit)
295306
self.assertTrue(statbuf.st_mode & S_IFREG)
296307

297308
gitdir = find_worktree_git_dir(dotgit)
298309
self.assertIsNotNone(gitdir)
299-
statbuf = stat(gitdir)
310+
statbuf = os.stat(gitdir)
300311
self.assertTrue(statbuf.st_mode & S_IFDIR)
301312

302313
def test_tree_entries_from_data_with_failing_name_decode_py3(self):

0 commit comments

Comments
 (0)