Skip to content

Commit e143f24

Browse files
committed
fix: properly use GitPython subcommands
1 parent 67c1ec3 commit e143f24

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/gitingest/clone.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
_add_token_to_url,
1313
check_repo_exists,
1414
checkout_partial_clone,
15-
create_git_auth_header,
1615
create_git_repo,
1716
ensure_git_installed,
1817
git_auth_context,
@@ -101,19 +100,19 @@ async def clone_repo(config: CloneConfig, *, token: str | None = None) -> None:
101100
"no_checkout": True,
102101
"depth": 1,
103102
}
104-
103+
105104
if partial_clone:
106105
# GitPython doesn't directly support --filter and --sparse in clone
107106
# We'll need to use git.Git() for the initial clone with these options
108107
git_cmd = git.Git()
109-
cmd_args = ["clone", "--single-branch", "--no-checkout", "--depth=1"]
108+
cmd_args = ["--single-branch", "--no-checkout", "--depth=1"]
110109
if partial_clone:
111110
cmd_args.extend(["--filter=blob:none", "--sparse"])
112111
cmd_args.extend([clone_url, local_path])
113-
git_cmd.execute(cmd_args)
112+
git_cmd.clone(*cmd_args)
114113
else:
115114
git.Repo.clone_from(clone_url, local_path, **clone_kwargs)
116-
115+
117116
logger.info("Git clone completed successfully")
118117
except git.GitCommandError as exc:
119118
msg = f"Git clone failed: {exc}"
@@ -128,7 +127,7 @@ async def clone_repo(config: CloneConfig, *, token: str | None = None) -> None:
128127
# Create repo object and perform operations
129128
try:
130129
repo = create_git_repo(local_path, url, token)
131-
130+
132131
# Ensure the commit is locally available
133132
logger.debug("Fetching specific commit", extra={"commit": commit})
134133
repo.git.fetch("--depth=1", "origin", commit)

src/gitingest/utils/git_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ async def checkout_partial_clone(config: CloneConfig, token: str | None) -> None
420420

421421
try:
422422
repo = create_git_repo(config.local_path, config.url, token)
423-
repo.git.execute(["sparse-checkout", "set", subpath])
423+
repo.git.sparse_checkout("set", subpath)
424424
except git.GitCommandError as exc:
425425
msg = f"Failed to configure sparse-checkout: {exc}"
426426
raise RuntimeError(msg) from exc

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ def _setup_gitpython_mocks(mocker: MockerFixture) -> dict[str, MagicMock]:
236236
mock_git_cmd.version.return_value = "git version 2.34.1"
237237
mock_git_cmd.config.return_value = "true"
238238
mock_git_cmd.execute.return_value = f"{DEMO_COMMIT}\trefs/heads/main\n"
239+
mock_git_cmd.ls_remote.return_value = f"{DEMO_COMMIT}\trefs/heads/main\n"
240+
mock_git_cmd.clone.return_value = ""
239241

240242
# Mock git.Repo class
241243
mock_repo = MagicMock()
@@ -245,6 +247,7 @@ def _setup_gitpython_mocks(mocker: MockerFixture) -> dict[str, MagicMock]:
245247
mock_repo.git.submodule = MagicMock()
246248
mock_repo.git.execute = MagicMock()
247249
mock_repo.git.config = MagicMock()
250+
mock_repo.git.sparse_checkout = MagicMock()
248251

249252
# Mock git.Repo.clone_from
250253
mock_clone_from = MagicMock(return_value=mock_repo)

tests/test_clone.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ async def test_clone_with_commit(repo_exists_true: AsyncMock, gitpython_mocks: d
4949
await clone_repo(clone_config)
5050

5151
repo_exists_true.assert_any_call(clone_config.url, token=None)
52-
52+
5353
# Verify GitPython calls were made
5454
mock_git_cmd = gitpython_mocks["git_cmd"]
5555
mock_repo = gitpython_mocks["repo"]
5656
mock_clone_from = gitpython_mocks["clone_from"]
57-
57+
5858
# Should have called version (for ensure_git_installed)
5959
mock_git_cmd.version.assert_called()
6060

0 commit comments

Comments
 (0)