Skip to content

Commit 75ad044

Browse files
iburelroot
authored andcommitted
refactor: Use GitPython instead of git in command line
1 parent c057f6e commit 75ad044

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/gitingest/clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from gitingest.config import DEFAULT_TIMEOUT
1111
from gitingest.utils.git_utils import (
12+
_add_token_to_url,
1213
check_repo_exists,
1314
checkout_partial_clone,
1415
create_git_repo,
@@ -109,7 +110,6 @@ async def clone_repo(config: CloneConfig, *, token: str | None = None) -> None:
109110
else:
110111
# For non-authenticated repos, use the standard GitPython method
111112
git.Repo.clone_from(url, local_path, **clone_kwargs)
112-
113113
logger.info("Git clone completed successfully")
114114
except git.GitCommandError as exc:
115115
msg = f"Git clone failed: {exc}"

src/gitingest/utils/git_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,37 @@ def _pick_commit_sha(lines: Iterable[str]) -> str | None:
529529
first_non_peeled = sha
530530

531531
return first_non_peeled # branch or lightweight tag (or None)
532+
533+
534+
def _add_token_to_url(url: str, token: str) -> str:
535+
"""Add authentication token to GitHub URL.
536+
537+
Parameters
538+
----------
539+
url : str
540+
The original GitHub URL.
541+
token : str
542+
The GitHub token to add.
543+
544+
Returns
545+
-------
546+
str
547+
The URL with embedded authentication.
548+
549+
"""
550+
from urllib.parse import urlparse, urlunparse
551+
552+
parsed = urlparse(url)
553+
# Add token as username in URL (GitHub supports this)
554+
netloc = f"x-oauth-basic:{token}@{parsed.hostname}"
555+
if parsed.port:
556+
netloc += f":{parsed.port}"
557+
558+
return urlunparse((
559+
parsed.scheme,
560+
netloc,
561+
parsed.path,
562+
parsed.params,
563+
parsed.query,
564+
parsed.fragment
565+
))

0 commit comments

Comments
 (0)