Skip to content

Commit

Permalink
Merge pull request #1745 from EliahKagan/ci-windows
Browse files Browse the repository at this point in the history
Test native Windows on CI
  • Loading branch information
Byron committed Nov 29, 2023
2 parents a2644da + e00fffc commit 96acc22
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 78 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ jobs:
command -v git python
git version
python --version
python -c 'import sys; print(sys.platform)'
python -c 'import os; print(os.name)'
python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly.
python -c 'import os, sys; print(f"sys.platform={sys.platform!r}, os.name={os.name!r}")'
- name: Test with pytest
run: |
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ permissions:

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- experimental: false

runs-on: ${{ matrix.os }}

defaults:
run:
shell: /bin/bash --noprofile --norc -exo pipefail {0}
shell: bash --noprofile --norc -exo pipefail {0}

steps:
- uses: actions/checkout@v4
Expand All @@ -34,6 +35,12 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: ${{ matrix.experimental }}

- name: Set up WSL (Windows)
if: startsWith(matrix.os, 'windows')
uses: Vampire/setup-wsl@v2.0.2
with:
distribution: Debian

- name: Prepare this repo for tests
run: |
./init-tests-after-clone.sh
Expand Down Expand Up @@ -61,9 +68,16 @@ jobs:
command -v git python
git version
python --version
python -c 'import sys; print(sys.platform)'
python -c 'import os; print(os.name)'
python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly.
python -c 'import os, sys; print(f"sys.platform={sys.platform!r}, os.name={os.name!r}")'
# For debugging hook tests on native Windows systems that may have WSL.
- name: Show bash.exe candidates (Windows)
if: startsWith(matrix.os, 'windows')
run: |
set +e
bash.exe -c 'printenv WSL_DISTRO_NAME; uname -a'
python -c 'import subprocess; subprocess.run(["bash.exe", "-c", "printenv WSL_DISTRO_NAME; uname -a"])'
continue-on-error: true

- name: Check types with mypy
run: |
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pytest-cov
pytest-instafail
pytest-mock
pytest-sugar
sumtypes
17 changes: 9 additions & 8 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
import glob
import io
import os
import os.path as osp
from unittest import mock

import pytest

from git import GitConfigParser
from git.config import _OMD, cp
from test.lib import (
TestCase,
fixture_path,
SkipTest,
)
from test.lib import with_rw_directory

import os.path as osp
from git.util import rmfile
from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory


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

@pytest.mark.xfail(
os.name == "nt",
reason='Second config._has_includes() assertion fails (for "config is included if path is matching git_dir")',
raises=AssertionError,
)
@with_rw_directory
def test_conditional_includes_from_git_dir(self, rw_dir):
# Initiate repository path.
Expand Down
30 changes: 13 additions & 17 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import ddt
import os
import os.path as osp
import shutil
import tempfile
from git import (
Repo,
GitCommandError,
Diff,
DiffIndex,
NULL_TREE,
Submodule,
)
from git.cmd import Git
from test.lib import (
TestBase,
StringProcessAdapter,
fixture,
)
from test.lib import with_rw_directory

import os.path as osp
import ddt
import pytest

from git import NULL_TREE, Diff, DiffIndex, GitCommandError, Repo, Submodule
from git.cmd import Git
from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory


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

@pytest.mark.xfail(
os.name == "nt",
reason='"Access is denied" when tearDown calls shutil.rmtree',
raises=PermissionError,
)
def test_diff_submodule(self):
"""Test that diff is able to correctly diff commits that cover submodule changes"""
# Init a temp git repo that will be referenced as a submodule.
Expand Down
11 changes: 9 additions & 2 deletions test/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

import pytest

from git.exc import GitCommandError
from test.lib import TestBase
from test.lib.helper import with_rw_directory

import os.path


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

@pytest.mark.xfail(
os.name == "nt",
reason=(
"IndexFile.from_tree is broken on Windows (related to NamedTemporaryFile), see #1630.\n"
"'git read-tree --index-output=...' fails with 'fatal: unable to write new index file'."
),
raises=GitCommandError,
)
@with_rw_directory
def test_references_and_objects(self, rw_dir):
# [1-test_references_and_objects]
Expand Down
17 changes: 14 additions & 3 deletions test/test_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

from io import BytesIO
from stat import S_IFDIR, S_IFREG, S_IFLNK, S_IXUSR
from os import stat
import os
import os.path as osp

import pytest

from git import Git
from git.exc import GitCommandError
from git.index import IndexFile
from git.index.fun import (
aggressive_tree_merge,
Expand Down Expand Up @@ -34,6 +37,14 @@ def _assert_index_entries(self, entries, trees):
assert (entry.path, entry.stage) in index.entries
# END assert entry matches fully

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

dotgit = osp.join(worktree_path, ".git")
statbuf = stat(dotgit)
statbuf = os.stat(dotgit)
self.assertTrue(statbuf.st_mode & S_IFREG)

gitdir = find_worktree_git_dir(dotgit)
self.assertIsNotNone(gitdir)
statbuf = stat(gitdir)
statbuf = os.stat(gitdir)
self.assertTrue(statbuf.st_mode & S_IFDIR)

def test_tree_entries_from_data_with_failing_name_decode_py3(self):
Expand Down

0 comments on commit 96acc22

Please sign in to comment.