Skip to content

Commit 0330d74

Browse files
committed
fix: enable core.longpaths on windows
1 parent 9a3a60b commit 0330d74

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

ggshield/utils/git_shell.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import platform
34
import re
45
import subprocess
56
from enum import Enum
@@ -204,8 +205,15 @@ def git(
204205
try:
205206
logger.debug("command=%s timeout=%d", command, timeout)
206207
result = subprocess.run(
207-
[_get_git_path(), "-c", "core.quotePath=false", "-c", "core.longpaths=true"]
208-
+ command,
208+
(
209+
[_get_git_path(), "-c", "core.quotePath=false"]
210+
+ (
211+
["-c", "core.longpaths=true"]
212+
if platform.system() == "Windows"
213+
else []
214+
)
215+
+ command
216+
),
209217
check=check,
210218
capture_output=True,
211219
timeout=timeout,

tests/unit/utils/test_git_shell.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import platform
3+
import subprocess
24
import tarfile
35
from io import BytesIO
46
from pathlib import Path
@@ -442,3 +444,37 @@ def test_git_ls_unstaged(tmp_path):
442444
# as relative to repo.path
443445
expected_paths = {x.relative_to(repo.path) for x in (repo_file, submodule_file)}
444446
assert {Path(x) for x in unstaged_files} == expected_paths
447+
448+
449+
def test_git_command_includes_longpaths_on_windows(monkeypatch):
450+
# GIVEN a mock for subprocess.run
451+
commands_run = []
452+
453+
def mock_subprocess_run(args, **kwargs):
454+
commands_run.append(args)
455+
456+
# Create a minimal mock result
457+
class Result:
458+
def __init__(self):
459+
self.stdout = b""
460+
self.stderr = b""
461+
462+
return Result()
463+
464+
monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
465+
466+
# WHEN executing any git command
467+
git(["status"])
468+
469+
# THEN the command includes core.longpaths=true if on Windows
470+
assert len(commands_run) == 1
471+
command = commands_run[0]
472+
longpaths_included = any(param == "core.longpaths=true" for param in command)
473+
if platform.system() == "Windows":
474+
assert (
475+
longpaths_included
476+
), f"core.longpaths=true not found in command: {command}"
477+
else:
478+
assert (
479+
not longpaths_included
480+
), f"core.longpaths=true found in command: {command}"

0 commit comments

Comments
 (0)