This update introduces full support for Git worktrees, allowing users to manage multiple isolated working copies within a single repository. This includes new functionality to list, add, remove, move, lock, and repair worktrees, significantly enhancing the repository's capability to handle parallel development streams. - Added `GitWorktree` structure definition across API contracts and Rust backend - Implemented full CRUD operations for worktrees in Tauri commands - Updated UI components (App.svelte, BranchPanel.svelte) to expose worktree management dialog
4.4 KiB
4.4 KiB
API Contract
The frontend calls Tauri commands with @tauri-apps/api/core.invoke.
Shared payloads
type FileStatusKind = "modified" | "added" | "deleted" | "renamed" | "untracked" | "conflicted" | "unknown";
interface GitStatus {
repo_path: string;
current_branch: string | null;
upstream: string | null;
ahead: number;
behind: number;
files: GitFileStatus[];
clean: boolean;
rebase_in_progress: boolean;
cherry_pick_in_progress: boolean;
merge_in_progress: boolean;
}
interface GitFileStatus {
path: string;
old_path: string | null;
staged: FileStatusKind | null;
unstaged: FileStatusKind | null;
}
interface GitBranch {
name: string;
current: boolean;
remote: boolean;
}
interface GitWorktree {
path: string;
head: string | null;
short_head: string | null;
branch: string | null;
bare: boolean;
detached: boolean;
locked: boolean;
lock_reason: string | null;
prunable: boolean;
prune_reason: string | null;
missing: boolean;
is_main: boolean;
is_current: boolean;
clean: boolean;
changed_files: number;
}
interface GitCommit {
hash: string;
short_hash: string;
summary: string;
author_name: string;
author_email: string;
date: string;
refs: string[];
files: GitCommitFile[];
}
interface GitCommitFile {
path: string;
old_path: string | null;
status: FileStatusKind;
}
interface GitRepositoryFile {
path: string;
tracked: boolean;
status: FileStatusKind | null;
}
Commands
The command list below includes the repository-management and synchronization API. The TypeScript wrappers in src/lib/git.ts are the authoritative full list.
open_repository(path: string): Promise<GitStatus>init_repository(path: string, initialBranch?: string): Promise<GitStatus>clone_repository(...): Promise<RepositoryBundle>get_status(path: string): Promise<GitStatus>list_branches(path: string): Promise<GitBranch[]>list_remotes(path: string): Promise<GitRemote[]>add_remote(path: string, name: string, url: string): Promise<GitRemote[]>update_remote(path: string, name: string, url: string): Promise<GitRemote[]>remove_remote(path: string, name: string): Promise<GitRemote[]>set_branch_upstream(path: string, branch: string, upstream?: string): Promise<GitStatus>delete_remote_branch(path: string, remote: string, branch: string): Promise<GitStatus>checkout_branch(path: string, branch: string): Promise<GitStatus>list_worktrees(path: string): Promise<GitWorktree[]>add_worktree(path: string, worktreePath: string, ...): Promise<GitWorktree[]>remove_worktree(path: string, worktreePath: string, force?: boolean): Promise<GitWorktree[]>move_worktree(path: string, worktreePath: string, destination: string): Promise<GitWorktree[]>lock_worktree(path: string, worktreePath: string, reason?: string): Promise<GitWorktree[]>unlock_worktree(path: string, worktreePath: string): Promise<GitWorktree[]>prune_worktrees(path: string): Promise<GitWorktree[]>repair_worktree(path: string, worktreePath: string): Promise<GitWorktree[]>stage_files(path: string, files: string[]): Promise<GitStatus>unstage_files(path: string, files: string[]): Promise<GitStatus>restore_files(path: string, files: string[], staged: boolean): Promise<GitStatus>commit(path: string, message: string): Promise<GitStatus>fetch(path: string, prune?: boolean, remote?: string): Promise<GitStatus>pull(path: string, strategy?: "merge" | "rebase" | "ff-only", remote?: string, branch?: string): Promise<GitStatus>push(path: string, forceWithLease?: boolean, remote?: string): Promise<GitStatus>list_commits(path: string, limit?: number): Promise<GitCommit[]>restore_to_commit(path: string, commit: string): Promise<GitStatus>restore_file_from_commit(path: string, commit: string, file: string): Promise<GitStatus>(thefileargument can also be a folder path)merge_branch(path: string, branch: string, strategy?: "default" | "squash" | "ff-only" | "no-ff"): Promise<GitStatus>merge_continue(path: string): Promise<GitStatus>merge_abort(path: string): Promise<GitStatus>revert_commit(path: string, commit: string): Promise<GitStatus>list_repository_files(path: string): Promise<GitRepositoryFile[]>list_file_history(path: string, file: string, limit?: number): Promise<GitCommit[]>(thefileargument can also be a folder path)