◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
2 changes: 1 addition & 1 deletion .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
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)'

- name: Test with pytest
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
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)'

- name: Check types with mypy
run: |
Expand Down
12 changes: 10 additions & 2 deletions git/compat.py
Original file line number Diff line number Diff line change
@@ -34,9 +34,17 @@
# ---------------------------------------------------------------------------


is_win: bool = os.name == "nt"
is_posix = os.name == "posix"
is_darwin = os.name == "darwin"
defenc = sys.getfilesystemencoding()


Expand Down
19 changes: 6 additions & 13 deletions git/config.py
Original file line number Diff line number Diff line change
@@ -7,28 +7,21 @@
"""Module containing module parser implementation able to properly read and write
configuration files."""

import sys
import abc
from functools import wraps
import inspect
from io import BufferedReader, IOBase
import logging
import os
import re
import fnmatch

from git.compat import (
defenc,
force_text,
is_win,
)

from git.util import LockFile

import os.path as osp

import configparser as cp

# typing-------------------------------------------------------

from typing import (
Expand Down Expand Up @@ -250,7 +243,7 @@ def items_all(self) -> List[Tuple[str, List[_T]]]:
def get_config_path(config_level: Lit_config_levels) -> str:
# We do not support an absolute path of the gitconfig on Windows.
# Use the global config instead.
if is_win and config_level == "system":
config_level = "global"

if config_level == "system":
Expand Down
22 changes: 7 additions & 15 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# NOTE: Autodoc hates it if this is a docstring.

from io import BytesIO
from pathlib import Path
import os
from stat import (
S_IFDIR,
S_IFLNK,
Expand All @@ -16,26 +17,17 @@
import subprocess

from git.cmd import PROC_CREATIONFLAGS, handle_process_output
from git.compat import (
defenc,
force_text,
force_bytes,
is_posix,
is_win,
safe_decode,
)
from git.exc import UnmergedEntriesError, HookExecutionError
from git.objects.fun import (
tree_to_stream,
traverse_tree_recursive,
traverse_trees_recursive,
)
from git.util import IndexFileSHA1Writer, finalize_process
from gitdb.base import IStream
from gitdb.typ import str_tree_type

import os.path as osp

from .typ import BaseIndexEntry, IndexEntry, CE_NAMEMASK, CE_STAGESHIFT
from .util import pack, unpack

Expand Down Expand Up @@ -96,7 +88,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
env["GIT_EDITOR"] = ":"
cmd = [hp]
try:
if is_win and not _has_file_extension(hp):
# Windows only uses extensions to determine how to open files
# (doesn't understand shebangs). Try using bash to run the hook.
relative_hp = Path(hp).relative_to(index.repo.working_dir).as_posix()
Expand All @@ -108,7 +100,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=index.repo.working_dir,
close_fds=is_posix,
creationflags=PROC_CREATIONFLAGS,
)
except Exception as ex:
Expand Down
8 changes: 2 additions & 6 deletions git/index/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

from functools import wraps
import os
import struct
import tempfile
from types import TracebackType

from git.compat import is_win

import os.path as osp


# typing ----------------------------------------------------------------------

from typing import Any, Callable, TYPE_CHECKING, Optional, Type
Expand Up @@ -58,7 +54,7 @@ def __exit__(
exc_tb: Optional[TracebackType],
) -> bool:
if osp.isfile(self.tmp_file_path):
if is_win and osp.exists(self.file_path):
os.remove(self.file_path)
os.rename(self.tmp_file_path, self.file_path)

Expand Down
7 changes: 3 additions & 4 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import git
from git.cmd import Git
from git.compat import defenc, is_win
from git.config import GitConfigParser, SectionConstraint, cp
from git.exc import (
BadName,
Expand Down Expand Up @@ -353,9 +353,8 @@ def _write_git_file_and_module_config(cls, working_tree_dir: PathLike, module_ab
"""
git_file = osp.join(working_tree_dir, ".git")
rela_path = osp.relpath(module_abspath, start=working_tree_dir)
if is_win:
if osp.isfile(git_file):
os.remove(git_file)
with open(git_file, "wb") as fp:
fp.write(("gitdir: %s" % rela_path).encode(defenc))

Loading
Toggle all file notes Toggle all file annotations