import type { SpawnOptions } from 'node:child_process'; import { z } from 'zod'; import type { Flavored } from './types.js'; /** * Basic git repository info. */ export interface GitInfo { commit: string | null; branch: string | null; } /** * Get basic git info (commit hash and branch name) without throwing. * Returns null values if git commands fail (e.g., not in a git repo). */ export declare const git_info_get: (options?: SpawnOptions) => Promise; export declare const GitOrigin: z.ZodString; export type GitOrigin = Flavored; export declare const GitBranch: z.ZodString; export type GitBranch = Flavored; /** * Returns the current git branch name. * @throws Error if the underlying git command fails */ export declare const git_current_branch_name: (options?: SpawnOptions) => Promise; /** * Checks if a remote git branch exists. * @throws Error if the `git ls-remote` command fails for a reason other than the branch not existing */ export declare const git_remote_branch_exists: (origin?: GitOrigin, branch?: GitBranch, options?: SpawnOptions) => Promise; /** * Checks if a local git branch exists. */ export declare const git_local_branch_exists: (branch: GitBranch, options?: SpawnOptions) => Promise; /** * Git workspace status flags indicating which types of changes are present. */ export interface GitWorkspaceStatus { unstaged_changes: boolean; staged_changes: boolean; untracked_files: boolean; } /** * Parses the output of `git status --porcelain -z` (v1 format) into a status object. * This is a pure function that can be tested independently. * * Format: XY path\0 where: * - X = staged status (index) * - Y = unstaged status (work tree) * - path = file path (unescaped with -z) * * Supported status codes: * - M = modified * - A = added * - D = deleted * - R = renamed * - C = copied * - T = type changed (regular file, symbolic link or submodule) * - U = unmerged * - ? = untracked * - ! = ignored * * For renames/copies: XY new\0old\0 (two NUL-separated paths) * * Note: This implementation treats submodules the same as regular files. * Submodule-specific status codes (lowercase m, ?) are interpreted as changes. * * @param stdout - the raw output from `git status --porcelain -z` */ export declare const git_parse_workspace_status: (stdout: string | null) => GitWorkspaceStatus; /** * Checks the git workspace status using a single `git status --porcelain -z` call. * The -z format provides more reliable parsing by using NUL separators and avoiding escaping. */ export declare const git_check_workspace: (options?: SpawnOptions) => Promise; /** * @returns `true` if the workspace has no changes at all */ export declare const git_workspace_is_clean: (status: GitWorkspaceStatus) => boolean; /** * @returns `true` if the workspace has no unstaged changes and no untracked files (staged changes are OK) */ export declare const git_workspace_is_fully_staged: (status: GitWorkspaceStatus) => boolean; /** * Converts a workspace status to a human-readable message. */ export declare const git_workspace_status_message: (status: GitWorkspaceStatus) => string; /** * @returns an error message if the git workspace has any unstaged or uncommitted changes, or `null` if it's clean */ export declare const git_check_clean_workspace: (options?: SpawnOptions) => Promise; /** * @returns an error message if the git workspace has any unstaged changes or untracked files, or `null` if fully staged */ export declare const git_check_fully_staged_workspace: (options?: SpawnOptions) => Promise; /** * Calls `git fetch`. * @throws Error if the underlying git command fails */ export declare const git_fetch: (origin?: GitOrigin, branch?: GitBranch, options?: SpawnOptions) => Promise; /** * Calls `git checkout`. * @returns the previous branch name, if it changed * @throws Error if the underlying git command fails */ export declare const git_checkout: (branch: GitBranch, options?: SpawnOptions) => Promise; /** * Calls `git pull`. * @throws Error if the underlying git command fails */ export declare const git_pull: (origin?: GitOrigin, branch?: GitBranch, options?: SpawnOptions) => Promise; /** * Calls `git push`. * @throws Error if the underlying git command fails */ export declare const git_push: (origin: GitOrigin, branch?: GitBranch, options?: SpawnOptions, set_upstream?: boolean) => Promise; /** * Calls `git push`, setting upstream if the remote branch does not yet exist. * @throws Error if the underlying git command fails */ export declare const git_push_to_create: (origin?: GitOrigin, branch?: GitBranch, options?: SpawnOptions) => Promise; /** * Deletes a branch locally. * @throws Error if the underlying git command fails */ export declare const git_delete_local_branch: (branch: GitBranch, options?: SpawnOptions) => Promise; /** * Deletes a branch remotely. * @throws Error if the underlying git command fails */ export declare const git_delete_remote_branch: (origin: GitOrigin, branch: GitBranch, options?: SpawnOptions) => Promise; /** * Resets the `target` branch back to its first commit both locally and remotely. */ export declare const git_reset_branch_to_first_commit: (origin: GitOrigin, branch: GitBranch, options?: SpawnOptions) => Promise; /** * Returns the branch's latest commit hash. * @throws Error if the underlying git command fails */ export declare const git_current_commit_hash: (branch?: string, options?: SpawnOptions) => Promise; /** * Returns the hash of the current branch's first commit. * @throws Error if the underlying git command fails */ export declare const git_current_branch_first_commit_hash: (options?: SpawnOptions) => Promise; /** * Returns the global git config setting for `pull.rebase`. */ export declare const git_check_setting_pull_rebase: (options?: SpawnOptions) => Promise; /** * Clones a branch locally to another directory and updates the origin to match the source. */ export declare const git_clone_locally: (origin: GitOrigin, branch: GitBranch, source_dir: string, target_dir: string, options?: SpawnOptions) => Promise; //# sourceMappingURL=git.d.ts.map