Git操作
Daytona SDKは、Sandbox内のgit
モジュールを通じてGitの組み込みサポートを提供します。本ガイドでは、利用可能なすべてのGit操作とベストプラクティスを解説します。
基本操作
Daytona SDKは、Sandbox(Daytonaが管理する隔離された一時的な実行環境)内でGitリポジトリのクローン、ステータス確認、管理を行う機能を提供します。git
モジュールを使ってGitリポジトリを操作できます。
ファイル操作と同様に、クローンの基準ディレクトリは現在のSandboxユーザーのホームです。例えば、workspace/repo
は /home/[username]/workspace/repo
を意味します。先頭を /
にすることで作業ディレクトリに絶対パスも指定できます。
リポジトリのクローン
Daytona SDKは、PythonおよびTypeScriptからSandboxにGitリポジトリをクローンできます。パブリック/プライベートリポジトリ、特定ブランチのクローンに対応し、Personal Access Tokenを用いた認証も可能です。
# Basic clonesandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo")
# Clone with authentication
sandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo", username="git", password="personal_access_token")
# Clone specific branch
sandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo", branch="develop")
// Basic cloneawait sandbox.git.clone( "https://github.com/user/repo.git", "workspace/repo");
// Clone with authenticationawait sandbox.git.clone( "https://github.com/user/repo.git", "workspace/repo", undefined, undefined, "git", "personal_access_token");
// Clone specific branchawait sandbox.git.clone( "https://github.com/user/repo.git", "workspace/repo", "develop");
リポジトリのステータス
Daytona SDKは、Sandbox内のGitリポジトリのステータス確認にも対応しています。PythonおよびTypeScriptで、現在のブランチ、変更ファイル、メインブランチに対する先行/遅行コミット数を取得できます。
# Get repository statusstatus = sandbox.git.status("workspace/repo")print(f"Current branch: {status.current_branch}")print(f"Commits ahead: {status.ahead}")print(f"Commits behind: {status.behind}")for file in status.file_status: print(f"File: {file.name}")
# List branches
response = sandbox.git.branches("workspace/repo")for branch in response.branches: print(f"Branch: {branch}")
// Get repository statusconst status = await sandbox.git.status("workspace/repo");console.log(`Current branch: ${status.currentBranch}`);console.log(`Commits ahead: ${status.ahead}`);console.log(`Commits behind: ${status.behind}`);status.fileStatus.forEach(file => { console.log(`File: ${file.name}`);});
// List branchesconst response = await sandbox.git.branches("workspace/repo");response.branches.forEach(branch => { console.log(`Branch: ${branch}`);});
ブランチ操作
Daytona SDK は、Git リポジトリのブランチ管理機能を提供します。ブランチの作成・切り替え・削除が可能です。
ブランチの管理
Daytona SDK では、Python と TypeScript から Git リポジトリのブランチを作成・切り替え・削除できます。
# 新しいブランチを作成sandbox.git.create_branch("workspace/repo", "feature/new-feature")
# ブランチを切り替えsandbox.git.checkout_branch("workspace/repo", "feature/new-feature")
# ブランチを削除sandbox.git.delete_branch("workspace/repo", "feature/old-feature")
// 新しいブランチを作成await sandbox.git.createBranch("workspace/repo", "feature/new-feature");
// ブランチを切り替えawait sandbox.git.checkoutBranch("workspace/repo", "feature/new-feature");
// ブランチを削除await sandbox.git.deleteBranch("workspace/repo", "feature/old-feature");
ステージングとコミット
Daytona SDK では、Git リポジトリの変更をステージしてコミットできます。Python と TypeScript から、特定のファイルのみ、またはすべての変更をステージし、メッセージ付きでコミットできます。
変更の扱い
# 特定のファイルをステージsandbox.git.add("workspace/repo", ["file1.txt", "file2.txt"])
# すべての変更をステージsandbox.git.add("workspace/repo", ["."])
# 変更をコミットsandbox.git.commit("workspace/repo", "feat: add new feature", "John Doe", "john@example.com")
// 特定のファイルをステージawait sandbox.git.add("workspace/repo", ["file1.txt", "file2.txt"]);
// すべての変更をステージawait sandbox.git.add("workspace/repo", ["."]);
// 変更をコミットawait sandbox.git.commit("workspace/repo", "feat: add new feature", "John Doe", "john@example.com");
リモート操作
Daytona SDK は Git のリモートリポジトリを扱う機能を提供します。変更のプッシュ、変更のプル、リモートの一覧表示が可能です。
リモートの操作
Daytona SDK は、Python と TypeScript から Git リポジトリに対してプッシュ、プル、リモートの一覧表示を行う機能を提供します。
# 変更をプッシュsandbox.git.push("workspace/repo")
# 変更をプルsandbox.git.pull("workspace/repo")
// 変更をプッシュawait sandbox.git.push("workspace/repo");
// 変更をプルawait sandbox.git.pull("workspace/repo");