Skip to content

Commit b3d6448

Browse files
fix(windows): warn if Git long path support is disabled, do not fail
1 parent a804aea commit b3d6448

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/gitingest/utils/git_utils.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import asyncio
66
import base64
7+
import ctypes
78
import os
89
import re
910
import sys
@@ -88,7 +89,6 @@ async def ensure_git_installed() -> None:
8889
------
8990
RuntimeError
9091
If Git is not installed or not accessible.
91-
If checking the long path setting fails on Windows.
9292
9393
"""
9494
try:
@@ -98,21 +98,20 @@ async def ensure_git_installed() -> None:
9898
raise RuntimeError(msg) from exc
9999
if sys.platform == "win32":
100100
try:
101-
stdout, _ = await run_command("git", "config", "--system", "core.longpaths")
102-
if stdout.decode().strip().lower() != "true":
103-
print(
104-
f"{Colors.BROWN}WARN{Colors.END}: {Colors.RED}Git clone may fail on Windows "
105-
f"due to long file paths:{Colors.END}",
106-
)
107-
print(f"{Colors.RED}To avoid this issue, consider enabling long path support with:{Colors.END}")
108-
print(f"{Colors.RED} git config --system core.longpaths true{Colors.END}")
109-
print(f"{Colors.RED}Note: This command may require administrator privileges.{Colors.END}")
110-
except RuntimeError as exc:
111-
msg = (
112-
"Unable to verify or access Git long path configuration. "
113-
"Run this application as Administrator or configure it manually."
114-
)
115-
raise RuntimeError(msg) from exc
101+
if ctypes.windll.shell32.IsUserAnAdmin():
102+
stdout, _ = await run_command("git", "config", "--system", "core.longpaths")
103+
if stdout.decode().strip().lower() == "true":
104+
return
105+
except RuntimeError:
106+
# Ignore if checking 'core.longpaths' fails due to lack of administrator rights.
107+
pass
108+
print(
109+
f"{Colors.BROWN}WARN{Colors.END}: {Colors.RED}Git clone may fail on Windows "
110+
f"due to long file paths:{Colors.END}",
111+
)
112+
print(f"{Colors.RED}To avoid this issue, consider enabling long path support with:{Colors.END}")
113+
print(f"{Colors.RED} git config --system core.longpaths true{Colors.END}")
114+
print(f"{Colors.RED}Note: This command may require administrator privileges.{Colors.END}")
116115

117116

118117
async def check_repo_exists(url: str, token: str | None = None) -> bool:

0 commit comments

Comments
 (0)