| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,63 +29,62 @@ | |||
| 29 | 29 | if sys.platform == "win32": | |
| 30 | 30 | __all__.append("to_native_path_windows") | |
| 31 | 31 | ||
| 32 | - from abc import abstractmethod | ||
| 33 | 32 | import contextlib | |
| 34 | - from functools import wraps | ||
| 35 | 33 | import getpass | |
| 36 | 34 | import logging | |
| 37 | 35 | import ntpath | |
| 38 | 36 | import os | |
| 39 | 37 | import os.path as osp | |
| 40 | - from pathlib import Path | ||
| 41 | 38 | import platform | |
| 42 | 39 | import re | |
| 43 | 40 | import shutil | |
| 44 | 41 | import stat | |
| 45 | 42 | import subprocess | |
| 46 | 43 | import time | |
| 47 | - from urllib.parse import urlsplit, urlunsplit | ||
| 48 | 44 | import warnings | |
| 49 | - | ||
| 50 | - # NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of | ||
| 51 | - # these be used indirectly through other GitPython modules, which avoids having to write | ||
| 52 | - # gitdb all the time in their imports. They are not in __all__, at least currently, | ||
| 53 | - # because they could be removed or changed at any time, and so should not be considered | ||
| 54 | - # conceptually public to code outside GitPython. Linters of course do not like it. | ||
| 55 | - from gitdb.util import ( | ||
| 56 | - LazyMixin, # noqa: F401 | ||
| 57 | - LockedFD, # noqa: F401 | ||
| 58 | - bin_to_hex, # noqa: F401 | ||
| 59 | - file_contents_ro, # noqa: F401 | ||
| 60 | - file_contents_ro_filepath, # noqa: F401 | ||
| 61 | - hex_to_bin, # noqa: F401 | ||
| 62 | - make_sha, | ||
| 63 | - to_bin_sha, # noqa: F401 | ||
| 64 | - to_hex_sha, # noqa: F401 | ||
| 65 | - ) | ||
| 45 | + from abc import abstractmethod | ||
| 46 | + from functools import wraps | ||
| 47 | + from pathlib import Path | ||
| 66 | 48 | ||
| 67 | 49 | # typing --------------------------------------------------------- | |
| 68 | - | ||
| 69 | 50 | from typing import ( | |
| 51 | + IO, | ||
| 52 | + TYPE_CHECKING, | ||
| 70 | 53 | Any, | |
| 71 | 54 | AnyStr, | |
| 72 | 55 | Callable, | |
| 73 | 56 | Dict, | |
| 74 | 57 | Generator, | |
| 75 | - IO, | ||
| 76 | 58 | Iterator, | |
| 77 | 59 | List, | |
| 78 | 60 | Optional, | |
| 79 | 61 | Pattern, | |
| 80 | 62 | Sequence, | |
| 81 | 63 | Tuple, | |
| 82 | - TYPE_CHECKING, | ||
| 83 | 64 | Type, | |
| 84 | 65 | TypeVar, | |
| 85 | 66 | Union, | |
| 86 | 67 | cast, | |
| 87 | 68 | overload, | |
| 88 | 69 | ) | |
| 70 | + from urllib.parse import urlsplit, urlunsplit | ||
| 71 | + | ||
| 72 | + # NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of | ||
| 73 | + # these be used indirectly through other GitPython modules, which avoids having to write | ||
| 74 | + # gitdb all the time in their imports. They are not in __all__, at least currently, | ||
| 75 | + # because they could be removed or changed at any time, and so should not be considered | ||
| 76 | + # conceptually public to code outside GitPython. Linters of course do not like it. | ||
| 77 | + from gitdb.util import ( | ||
| 78 | + LazyMixin, # noqa: F401 | ||
| 79 | + LockedFD, # noqa: F401 | ||
| 80 | + bin_to_hex, # noqa: F401 | ||
| 81 | + file_contents_ro, # noqa: F401 | ||
| 82 | + file_contents_ro_filepath, # noqa: F401 | ||
| 83 | + hex_to_bin, # noqa: F401 | ||
| 84 | + make_sha, | ||
| 85 | + to_bin_sha, # noqa: F401 | ||
| 86 | + to_hex_sha, # noqa: F401 | ||
| 87 | + ) | ||
| 89 | 88 | ||
| 90 | 89 | if TYPE_CHECKING: | |
| 91 | 90 | from git.cmd import Git | |
@@ -94,9 +93,9 @@ | |||
| 94 | 93 | from git.repo.base import Repo | |
| 95 | 94 | ||
| 96 | 95 | from git.types import ( | |
| 96 | + HSH_TD, | ||
| 97 | 97 | Files_TD, | |
| 98 | 98 | Has_id_attribute, | |
| 99 | - HSH_TD, | ||
| 100 | 99 | Literal, | |
| 101 | 100 | PathLike, | |
| 102 | 101 | Protocol, | |
@@ -419,11 +418,13 @@ def _validate_repo_path(path: PathLike, mode: Union[int, None] = None) -> None: | |||
| 419 | 418 | hfs_name = part.translate(_HFS_IGNORABLES).lower() | |
| 420 | 419 | if ntfs_name in (".git", "git~1") or hfs_name == ".git": | |
| 421 | 420 | raise ValueError("Repository path aliases Git metadata: %r" % name) | |
| 422 | - aliases_gitmodules = ( | ||
| 423 | - ntfs_name == ".gitmodules" or hfs_name == ".gitmodules" or ntfs_name in _NTFS_DOTGITMODULES_SHORT_NAMES | ||
| 424 | - ) | ||
| 425 | - if aliases_gitmodules and mode is not None and stat.S_ISLNK(mode): | ||
| 426 | - raise ValueError("Symbolic link aliases the submodule configuration: %r" % name) | ||
| 421 | + if mode is not None and stat.S_ISLNK(mode): | ||
| 422 | + if ( | ||
| 423 | + ntfs_name == ".gitmodules" | ||
| 424 | + or hfs_name == ".gitmodules" | ||
| 425 | + or ntfs_name in _NTFS_DOTGITMODULES_SHORT_NAMES | ||
| 426 | + ): | ||
| 427 | + raise ValueError("Symbolic link aliases the submodule configuration: %r" % name) | ||
| 427 | 428 | ||
| 428 | 429 | ||
| 429 | 430 | def assure_directory_exists(path: PathLike, is_file: bool = False) -> bool: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -408,20 +408,26 @@ def _cmp_tree_index(self, tree, index): | |||
| 408 | 408 | ||
| 409 | 409 | @with_rw_repo("0.1.6") | |
| 410 | 410 | def test_index_lock_handling(self, rw_repo): | |
| 411 | - def add_bad_blob(): | ||
| 412 | - rw_repo.index.add([Blob(rw_repo, b"f" * 20, "bad-permissions", "foo")]) | ||
| 413 | - | ||
| 414 | - try: | ||
| 415 | - ## First, fail on purpose adding into index. | ||
| 416 | - add_bad_blob() | ||
| 417 | - except Exception as ex: | ||
| 418 | - assert "required argument is not an integer" in str(ex) | ||
| 419 | - | ||
| 420 | - ## The second time should not fail due to stray lock file. | ||
| 421 | - try: | ||
| 422 | - add_bad_blob() | ||
| 423 | - except Exception as ex: | ||
| 424 | - assert "index.lock' could not be obtained" not in str(ex) | ||
| 411 | + index = rw_repo.index | ||
| 412 | + index_path = Path(index.path) | ||
| 413 | + lock_path = Path(str(index_path) + ".lock") | ||
| 414 | + before = index_path.read_bytes() | ||
| 415 | + | ||
| 416 | + def fail_serialize(stream, ignore_extension_data): | ||
| 417 | + assert lock_path.exists() | ||
| 418 | + stream.write(b"partial index") | ||
| 419 | + raise OSError("simulated index write failure") | ||
| 420 | + | ||
| 421 | + with mock.patch.object(IndexFile, "_serialize", side_effect=fail_serialize): | ||
| 422 | + for _ in range(2): | ||
| 423 | + with pytest.raises(OSError, match="simulated index write failure"): | ||
| 424 | + index.write() | ||
| 425 | + assert not lock_path.exists() | ||
| 426 | + assert index_path.read_bytes() == before | ||
| 427 | + | ||
| 428 | + index.add([Blob(rw_repo, b"f" * 20, 0o100644, "foo")]) | ||
| 429 | + assert not lock_path.exists() | ||
| 430 | + assert rw_repo.index.entries[("foo", 0)].mode == 0o100644 | ||
| 425 | 431 | ||
| 426 | 432 | @with_rw_repo("0.1.6") | |
| 427 | 433 | def test_read_tree_methods_reject_index_output(self, rw_repo): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments