Skip to content

Commit 3ff4303

Browse files
authored
Merge pull request #1057 from GitGuardian/severine/handle-longpaths
fix: enable core.longpaths on git commands
2 parents 2d14af9 + b26d6b8 commit 3ff4303

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fix ggshield crashing on Windows when doing big merges (#1032).

ggshield/utils/git_shell.py

Lines changed: 10 additions & 1 deletion
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,7 +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"] + 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+
),
208217
check=check,
209218
capture_output=True,
210219
timeout=timeout,

tests/unit/utils/test_git_shell.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import platform
23
import tarfile
34
from io import BytesIO
45
from pathlib import Path
56
from typing import Optional
7+
from unittest.mock import Mock, patch
68

79
import pytest
810

@@ -442,3 +444,22 @@ 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+
@patch("subprocess.run", return_value=Mock(stdout=b""))
450+
def test_git_command_includes_longpaths_on_windows(mock_run):
451+
# GIVEN any git command
452+
git(["status"])
453+
mock_run.assert_called_once()
454+
455+
# THEN the command includes core.longpaths=true if on Windows
456+
command = mock_run.call_args[0][0]
457+
longpaths_included = any(param == "core.longpaths=true" for param in command)
458+
if platform.system() == "Windows":
459+
assert (
460+
longpaths_included
461+
), f"core.longpaths=true not found in command: {command}"
462+
else:
463+
assert (
464+
not longpaths_included
465+
), f"core.longpaths=true found in command: {command}"

0 commit comments

Comments
 (0)