AsyncGit
class AsyncGit()サンドボックス内でGit操作を提供します。
例:
# リポジトリをクローンawait sandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo")
# リポジトリのステータスを確認status = await sandbox.git.status("workspace/repo")print(f"Modified files: {status.modified}")
# 変更をステージしてコミットawait sandbox.git.add("workspace/repo", ["file.txt"])await sandbox.git.commit( path="workspace/repo", message="Update file", author="John Doe", email="john@example.com")AsyncGit.init
def __init__(sandbox_id: str, toolbox_api: ToolboxApi, get_root_dir: Callable[[], Awaitable[str]])新しいGitハンドラーインスタンスを初期化します。
引数:
sandbox_idstr - サンドボックスID。toolbox_apiToolboxApi - サンドボックス操作用のAPIクライアント。get_root_dirCallable[[], str] - サンドボックスのデフォルトのルートディレクトリを取得する関数。
AsyncGit.add
@intercept_errors(message_prefix="Failed to add files: ")async def add(path: str, files: List[str]) -> None指定したファイルを次回のコミットに向けてステージします。コマンドラインで 「git add」を実行するのと同様です。
引数:
pathstr - Gitリポジトリのルートへのパス。相対パスはユーザーの ルートディレクトリを基準に解決されます。filesList[str] - リポジトリルートからの相対パスで、ステージするファイルまたはディレクトリのリスト。
例:
# 単一ファイルをステージawait sandbox.git.add("workspace/repo", ["file.txt"])
# 複数ファイルをステージawait sandbox.git.add("workspace/repo", [ "src/main.py", "tests/test_main.py", "README.md"])AsyncGit.branches
@intercept_errors(message_prefix="Failed to list branches: ")async def branches(path: str) -> ListBranchResponseリポジトリ内のブランチを一覧表示します。
引数:
pathstr - Gitリポジトリのルートへのパス。相対パスはユーザーの ルートディレクトリを基準に解決されます。
返り値:
ListBranchResponse- リポジトリ内のブランチ一覧。
例:
response = await sandbox.git.branches("workspace/repo")print(f"Branches: {response.branches}")AsyncGit.clone
@intercept_errors(message_prefix="Failed to clone repository: ")async def clone(url: str, path: str, branch: Optional[str] = None, commit_id: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None) -> None指定したパスにGitリポジトリをクローンします。特定のブランチまたはコミットの クローンに対応し、認証情報が指定された場合はリモートリポジトリへの 認証も可能です。
引数:
urlstr - クローン元のリポジトリURL。pathstr - リポジトリをクローンするパス。相対パスはユーザーの ルートディレクトリを基準に解決されます。branchOptional[str] - クローンするブランチ。未指定の場合は デフォルトブランチをクローンします。commit_idOptional[str] - クローンするコミット。指定された場合、 リポジトリはこのコミットのdetached HEAD状態になります。usernameOptional[str] - 認証用のGitユーザー名。passwordOptional[str] - 認証用のGitパスワードまたはトークン。
例:
# デフォルトブランチをクローンawait sandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo")
# 認証付きで特定のブランチをクローンawait sandbox.git.clone( url="https://github.com/user/private-repo.git", path="workspace/private", branch="develop", username="user", password="token")
# 特定のコミットをクローンawait sandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo-old", commit_id="abc123")AsyncGit.commit
@intercept_errors(message_prefix="Failed to commit changes: ")async def commit(path: str, message: str, author: str, email: str, allow_empty: bool = False) -> GitCommitResponseステージ済みの変更から新しいコミットを作成します。コミットする前に必ず add() メソッドで変更をステージしてください。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。messagestr - 変更内容を説明するコミットメッセージ。authorstr - コミット作者の名前。emailstr - コミット作者のメールアドレス。allow_emptybool, optional - 変更がステージされていない場合でも空のコミットの作成を許可します。デフォルトは False。
例:
# 変更をステージしてコミットするawait sandbox.git.add("workspace/repo", ["README.md"])await sandbox.git.commit( path="workspace/repo", message="Update documentation", author="John Doe", email="john@example.com", allow_empty=True)AsyncGit.push
@intercept_errors(message_prefix="Failed to push changes: ")async def push(path: str, username: Optional[str] = None, password: Optional[str] = None) -> None現在のブランチのすべてのローカルコミットをリモートリポジトリにプッシュします。リモートリポジトリが認証を必要とする場合は、ユーザー名とパスワード/トークンを指定してください。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。usernameOptional[str] - 認証用の Git ユーザー名。passwordOptional[str] - 認証用の Git パスワードまたはトークン。
例:
# 認証なしでプッシュ(公開リポジトリや SSH の場合)await sandbox.git.push("workspace/repo")
# 認証ありでプッシュawait sandbox.git.push( path="workspace/repo", username="user", password="github_token")AsyncGit.pull
@intercept_errors(message_prefix="Failed to pull changes: ")async def pull(path: str, username: Optional[str] = None, password: Optional[str] = None) -> Noneリモートリポジトリから変更をプルします。リモートリポジトリが認証を必要とする場合は、ユーザー名とパスワード/トークンを指定してください。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。usernameOptional[str] - 認証用の Git ユーザー名。passwordOptional[str] - 認証用の Git パスワードまたはトークン。
例:
# 認証なしでプルawait sandbox.git.pull("workspace/repo")
# 認証ありでプルawait sandbox.git.pull( path="workspace/repo", username="user", password="github_token")AsyncGit.status
@intercept_errors(message_prefix="Failed to get status: ")async def status(path: str) -> GitStatus現在の Git リポジトリのステータスを取得します。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。
戻り値:
GitStatus- 以下を含むリポジトリのステータス情報:- current_branch: 現在のブランチ名
- file_status: ファイルのステータス一覧
- ahead: リモートに未プッシュのローカルコミット数
- behind: ローカルに未プルのリモートコミット数
- branch_published: ブランチがリモートリポジトリに公開済みかどうか
例:
status = await sandbox.git.status("workspace/repo")print(f"On branch: {status.current_branch}")print(f"Commits ahead: {status.ahead}")print(f"Commits behind: {status.behind}")AsyncGit.checkout_branch
@intercept_errors(message_prefix="Failed to checkout branch: ")async def checkout_branch(path: str, branch: str) -> Noneリポジトリでブランチをチェックアウトします。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。branchstr - チェックアウトするブランチ名
例:
# ブランチをチェックアウトawait sandbox.git.checkout_branch("workspace/repo", "feature-branch")AsyncGit.create_branch
@intercept_errors(message_prefix="Failed to create branch: ")async def create_branch(path: str, name: str) -> Noneリポジトリでブランチを作成します。
引数:
pathstr - Git リポジトリのルートへのパス。相対パスはユーザーのルートディレクトリを基準に解決されます。namestr - 作成する新しいブランチ名
例:
# 新しいブランチを作成await sandbox.git.create_branch("workspace/repo", "new-feature")AsyncGit.delete_branch
@intercept_errors(message_prefix="Failed to delete branch: ")async def delete_branch(path: str, name: str) -> Noneリポジトリ内のブランチを削除します。
引数:
pathstr - Gitリポジトリのルートへのパス。相対パスはユーザーの ルートディレクトリを基準に解決されます。namestr - 削除するブランチ名
例:
# ブランチを削除await sandbox.git.delete_branch("workspace/repo", "old-feature")GitCommitResponse
class GitCommitResponse()Git の commit 操作に対するレスポンス。
属性:
shastr - コミットの SHA