|
15 | 15 | GitBranchesResponse, |
16 | 16 | GitCheckoutRequest, |
17 | 17 | GitCheckoutResponse, |
| 18 | + GitCommandResponse, |
| 19 | + GitCommitRequest, |
18 | 20 | GitCreateBranchRequest, |
19 | 21 | GitCreateBranchResponse, |
20 | 22 | GitDiffResponse, |
21 | | - GitPushPullResponse, |
22 | 23 | GitRemoteUrlResponse, |
23 | 24 | IDEUrlResponse, |
24 | 25 | SandboxFilesMetadataResponse, |
@@ -53,7 +54,7 @@ def _git_cd_prefix(cwd: str | None = None) -> str: |
53 | 54 | status_code=status.HTTP_400_BAD_REQUEST, |
54 | 55 | detail="Invalid cwd path", |
55 | 56 | ) |
56 | | - return f"cd '{cwd}'; " |
| 57 | + return f"cd '{cwd}' && " |
57 | 58 |
|
58 | 59 |
|
59 | 60 | @router.get("/{sandbox_id}/preview-links", response_model=PreviewLinksResponse) |
@@ -482,50 +483,65 @@ async def checkout_git_branch( |
482 | 483 | ) |
483 | 484 |
|
484 | 485 |
|
485 | | -async def _run_git_push_pull( |
| 486 | +async def _run_git_command( |
486 | 487 | sandbox_id: str, |
487 | 488 | command: str, |
488 | 489 | sandbox_service: SandboxService, |
489 | 490 | cwd: str | None = None, |
490 | | -) -> GitPushPullResponse: |
| 491 | +) -> GitCommandResponse: |
491 | 492 | try: |
492 | 493 | cd_prefix = _git_cd_prefix(cwd) |
493 | 494 | result = await sandbox_service.execute_command( |
494 | 495 | sandbox_id, |
495 | 496 | f"{cd_prefix}{command} 2>&1", |
496 | 497 | ) |
497 | 498 | if result.exit_code != 0: |
498 | | - return GitPushPullResponse( |
| 499 | + return GitCommandResponse( |
499 | 500 | success=False, |
500 | 501 | output="", |
501 | 502 | error=result.stdout.strip() or result.stderr.strip(), |
502 | 503 | ) |
503 | | - return GitPushPullResponse(success=True, output=result.stdout.strip()) |
| 504 | + return GitCommandResponse(success=True, output=result.stdout.strip()) |
504 | 505 | except SandboxException as e: |
505 | 506 | raise HTTPException( |
506 | 507 | status_code=status.HTTP_400_BAD_REQUEST, |
507 | 508 | detail=str(e), |
508 | 509 | ) |
509 | 510 |
|
510 | 511 |
|
511 | | -@router.post("/{sandbox_id}/git/push", response_model=GitPushPullResponse) |
| 512 | +@router.post("/{sandbox_id}/git/push", response_model=GitCommandResponse) |
512 | 513 | async def git_push( |
513 | 514 | sandbox_id: str = Depends(validate_sandbox_ownership), |
514 | 515 | sandbox_service: SandboxService = Depends(get_sandbox_service), |
515 | 516 | cwd: str | None = Query(None), |
516 | | -) -> GitPushPullResponse: |
517 | | - return await _run_git_push_pull( |
| 517 | +) -> GitCommandResponse: |
| 518 | + return await _run_git_command( |
518 | 519 | sandbox_id, "git push -u origin HEAD", sandbox_service, cwd |
519 | 520 | ) |
520 | 521 |
|
521 | 522 |
|
522 | | -@router.post("/{sandbox_id}/git/pull", response_model=GitPushPullResponse) |
| 523 | +@router.post("/{sandbox_id}/git/pull", response_model=GitCommandResponse) |
523 | 524 | async def git_pull( |
524 | 525 | sandbox_id: str = Depends(validate_sandbox_ownership), |
525 | 526 | sandbox_service: SandboxService = Depends(get_sandbox_service), |
526 | 527 | cwd: str | None = Query(None), |
527 | | -) -> GitPushPullResponse: |
528 | | - return await _run_git_push_pull(sandbox_id, "git pull", sandbox_service, cwd) |
| 528 | +) -> GitCommandResponse: |
| 529 | + return await _run_git_command(sandbox_id, "git pull", sandbox_service, cwd) |
| 530 | + |
| 531 | + |
| 532 | +@router.post("/{sandbox_id}/git/commit", response_model=GitCommandResponse) |
| 533 | +async def git_commit( |
| 534 | + request: GitCommitRequest, |
| 535 | + sandbox_id: str = Depends(validate_sandbox_ownership), |
| 536 | + sandbox_service: SandboxService = Depends(get_sandbox_service), |
| 537 | +) -> GitCommandResponse: |
| 538 | + msg = request.message.replace("'", "'\\''") |
| 539 | + return await _run_git_command( |
| 540 | + sandbox_id, |
| 541 | + f"git add -A && git commit -m '{msg}'", |
| 542 | + sandbox_service, |
| 543 | + request.cwd, |
| 544 | + ) |
529 | 545 |
|
530 | 546 |
|
531 | 547 | @router.post("/{sandbox_id}/git/create-branch", response_model=GitCreateBranchResponse) |
|
0 commit comments