From 6e477e3a06e4b11d43ea118a9f18cae03fa211fd Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 14 Nov 2023 00:41:57 -0500 Subject: [PATCH] Add xfail marks for IndexFile.from_tree failures 8 of the tests that fail on native Windows systems fail due to IndexFile.from_tree being broken on Windows, causing #1630. This commit marks those tests as xfail. This is part, though not all, of the changes to get CI test jobs for native Windows that are passing, to guard against new regressions and to allow the code and tests to be gradually fixed (see discussion in #1654). When fixing the bug, this commit can be reverted. --- test/test_docs.py | 11 +++++++++-- test/test_fun.py | 17 ++++++++++++++--- test/test_index.py | 40 ++++++++++++++++++++++++++++++++++++++++ test/test_refs.py | 11 +++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/test/test_docs.py b/test/test_docs.py index 2f4b2e8d8..2ff1c794a 100644 --- a/test/test_docs.py +++ b/test/test_docs.py @@ -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): @@ -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] diff --git a/test/test_fun.py b/test/test_fun.py index 566bc9aae..8ea5b7e46 100644 --- a/test/test_fun.py +++ b/test/test_fun.py @@ -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, @@ -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 @@ -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): diff --git a/test/test_index.py b/test/test_index.py index 3d1042be8..9fe35d42b 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -179,6 +179,14 @@ def add_bad_blob(): except Exception as ex: assert "index.lock' could not be obtained" not in str(ex) + @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_repo("0.1.6") def test_index_file_from_tree(self, rw_repo): common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541" @@ -229,6 +237,14 @@ def test_index_file_from_tree(self, rw_repo): # END for each blob self.assertEqual(num_blobs, len(three_way_index.entries)) + @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_repo("0.1.6") def test_index_merge_tree(self, rw_repo): # A bit out of place, but we need a different repo for this: @@ -291,6 +307,14 @@ def test_index_merge_tree(self, rw_repo): self.assertEqual(len(unmerged_blobs), 1) self.assertEqual(list(unmerged_blobs.keys())[0], manifest_key[0]) + @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_repo("0.1.6") def test_index_file_diffing(self, rw_repo): # Default Index instance points to our index. @@ -425,6 +449,14 @@ def _count_existing(self, repo, files): # END num existing helper + @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_repo("0.1.6") def test_index_mutation(self, rw_repo): index = rw_repo.index @@ -778,6 +810,14 @@ def make_paths(): for absfile in absfiles: assert osp.isfile(absfile) + @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_repo("HEAD") def test_compare_write_tree(self, rw_repo): """Test writing all trees, comparing them for equality.""" diff --git a/test/test_refs.py b/test/test_refs.py index 6ee385007..a1573c11b 100644 --- a/test/test_refs.py +++ b/test/test_refs.py @@ -4,8 +4,11 @@ # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ from itertools import chain +import os from pathlib import Path +import pytest + from git import ( Reference, Head, @@ -215,6 +218,14 @@ def test_head_checkout_detached_head(self, rw_repo): assert isinstance(res, SymbolicReference) assert res.name == "HEAD" + @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_repo("0.1.6") def test_head_reset(self, rw_repo): cur_head = rw_repo.head