git-aiflow
Version:
🚀 An AI-powered workflow automation tool for effortless Git-based development, combining smart GitLab/GitHub merge & pull request creation with Conan package management.
360 lines • 13 kB
TypeScript
/**
* Git file status interface
*/
export interface GitFileStatus {
/** File path relative to repository root */
path: string;
/** Index status (staged changes) */
indexStatus: string;
/** Working tree status (unstaged changes) */
workTreeStatus: string;
/** Whether file is untracked */
isUntracked: boolean;
/** Human readable status description */
statusDescription: string;
}
/**
* Git operations service
*/
export declare class GitService {
private readonly shell;
private static readonly protocolCache;
private static readonly instances;
private remote_name?;
private remote_urls;
private constructor();
/**
* Safely checkout to the specified branch with the following steps:
* 1. Automatically stash working directory and staged changes (including untracked files)
* 2. Fetch remote branch and validate its existence
* 3. If local branch exists: checkout and attempt fast-forward to remote/<branch>
* - Only fast-forward (--ff-only) to avoid merge commits
* - If fast-forward fails, preserve current commit with warning
* 4. If local branch doesn't exist: create tracking branch from remote/<branch>
* 5. Finally attempt stash pop (if conflicts occur, preserve and prompt for manual resolution)
*
* @param branchName The name of the branch to checkout
* @returns True if checkout was successful, false otherwise
*/
checkout(branchName: string): boolean;
/**
* Gets the current HEAD commit hash.
* @returns The short commit hash or empty string if failed
*/
private getCurrentHead;
/**
* Handles uncommitted changes by stashing them if necessary.
* @param branchName The target branch name for stash message
* @returns Object containing stash status
*/
private handleWorkingDirectoryChanges;
/**
* Fetches and validates the remote branch exists.
* @param branchName The branch name to fetch and validate
* @param remoteName The remote name to use
* @param pushedStash Whether stash was pushed (for rollback)
* @returns True if remote branch exists and was fetched successfully
*/
private fetchAndValidateRemoteBranch;
/**
* Checks if local branch exists.
* @param branchName The branch name to check
* @returns True if local branch exists
*/
private checkLocalBranchExists;
/**
* Checkouts to existing local branch and attempts fast-forward.
* @param branchName The branch name to checkout
* @param remoteName The remote name to use
* @param pushedStash Whether stash was pushed (for rollback)
* @returns True if checkout was successful, false otherwise
*/
private checkoutExistingBranch;
/**
* Creates a new tracking branch from remote.
* @param branchName The branch name to create
* @param remoteName The remote name to use
* @param pushedStash Whether stash was pushed (for rollback)
* @returns True if branch creation was successful, false otherwise
*/
private createTrackingBranch;
/**
* Restores working directory changes from stash if applicable.
* @param pushedStash Whether stash was pushed
*/
private restoreWorkingDirectoryChanges;
/**
* Logs the completion of checkout operation.
* @param previousHead The previous HEAD commit hash
* @param branchName The target branch name
*/
private logCheckoutCompletion;
/**
* Rolls back stash if it was pushed.
* @param pushedStash Whether stash was pushed
*/
private rollbackStash;
/**
* Executes a git command and returns structured result.
* @param command The git command to execute
* @param description Optional description for logging
* @returns Object containing success status and output
*/
private executeGitCommand;
getUserName(): string;
/**
* Get git diff of staged changes
* @param options Diff options
* @returns Git diff output
*/
getDiff(options?: {
includeBinary?: boolean;
nameOnly?: boolean;
}): string;
/**
* Get diff excluding binary files
* @returns Git diff output with binary files excluded
*/
private getDiffExcludingBinary;
/**
* Check if a file is binary
* @param filePath File path to check
* @param options Options for binary detection
* @returns True if file is binary, false otherwise
*/
private isBinaryFile;
/**
* Get git diff of specific files (unstaged changes)
* @param filePaths Array of file paths to check diff for
* @param options Diff options
* @returns Git diff output
*/
getDiffForFiles(filePaths: string[], options?: {
includeBinary?: boolean;
}): string;
/**
* Get diff for specific files excluding binary files
* @param filePaths Array of file paths to check diff for
* @returns Git diff output with binary files excluded
*/
private getDiffForFilesExcludingBinary;
/**
* Get diff between two branches
* @param baseBranch Base branch name
* @param targetBranch Target branch name
* @param options Diff options
* @returns Git diff output between branches
*/
getDiffBetweenBranches(baseBranch: string, targetBranch: string, options?: {
includeBinary?: boolean;
}): string;
/**
* Try to get diff between branches using different formats
* @param baseBranch Base branch name
* @param targetBranch Target branch name
* @param extraArgs Extra arguments for git diff
* @returns Diff output or null if failed
*/
private tryGetDiffBetweenBranches;
/**
* Get diff between branches excluding binary files
* @param baseBranch Base branch name
* @param targetBranch Target branch name
* @returns Git diff output with binary files excluded
*/
private getDiffBetweenBranchesExcludingBinary;
/**
* Get list of changed files between two branches
* @param baseBranch Base branch name
* @param targetBranch Target branch name
* @returns Array of changed file paths
*/
getChangedFilesBetweenBranches(baseBranch: string, targetBranch: string): string[];
/**
* Add specific file to staging area
* @param filePath File path to add
*/
addFile(filePath: string): void;
/**
* Add multiple files to staging area
* @param filePaths Array of file paths to add
*/
addFiles(filePaths: string[], batchSize?: number): void;
/**
* Create a new branch
* @param branchName Branch name to create
*/
createBranch(branchName: string): void;
/**
* Commit staged changes
* @param message Commit message
*/
commit(message: string): void;
/**
* Push current branch to remote
* @param branchName Branch name to push
*/
push(branchName: string): void;
/**
* Create branch, commit and push (legacy method)
* @param branch Branch name
* @param message Commit message
*/
commitAndPush(branch: string, message: string): boolean;
getChangedFiles(limit?: number): string[];
/**
* Get git repository root directory
*/
getRepositoryRoot(): string;
/**
* Gets the default remote name for the current repository.
* Tries to detect the most appropriate remote in the following order:
* 1. 'origin' (most common)
* 2. 'upstream' (common in fork workflows)
* 3. First available remote
* @returns The default remote name or 'origin' as fallback
*/
getRemoteName(): string;
/**
* Get remote URL for specified remote
*/
getRemoteUrl(remoteName?: string): string;
/**
* Extract hostname from Git remote URL
* @param remoteUrl Git remote URL (optional, will get current remote if not provided)
* @returns Hostname (e.g., 'github.com', 'gitlab.example.com')
*/
extractHostnameFromRemoteUrl(remoteUrl?: string): string;
/**
* Extract base URL from Git remote URL with protocol detection
* @param remoteUrl Git remote URL (optional, will get current remote if not provided)
* @returns Base URL (e.g., "https://github.com", "https://gitlab.example.com")
*/
extractBaseUrlFromRemoteUrl(remoteUrl?: string): Promise<string>;
/**
* Parse project path from Git remote URL
* @param remoteUrl Git remote URL (optional, will get current remote if not provided)
* @returns Project path (e.g., "user/repo")
*/
parseProjectPathFromUrl(remoteUrl?: string): string | null;
/**
* Detect the appropriate protocol (HTTPS/HTTP) for a given hostname
* @param hostname The hostname to check
* @returns Base URL with detected protocol
*/
private detectProtocolForHost;
/**
* Probe a hostname to detect HTTPS/HTTP support in background
* Updates the cache when detection is complete
* @param hostname The hostname to probe
* @returns Promise<string> The URL with the detected protocol
*/
private probeProtocolForHost;
/**
* Get detected protocol for hostname (synchronous, may return cached result)
* @param hostname The hostname to check
* @returns Base URL with detected protocol
*/
getDetectedProtocolForHost(hostname: string): Promise<string>;
/**
* Clear protocol cache for a specific hostname or all hostnames
* @param hostname Optional hostname to clear, if not provided clears all cache
*/
static clearProtocolCache(hostname?: string): void;
/**
* Get current protocol cache (for debugging)
* @returns Copy of current cache entries
*/
static getProtocolCache(): Record<string, string>;
/**
* Force re-detection of protocol for hostname (asynchronous)
* @param hostname The hostname to re-detect
* @returns Promise<Base URL with detected protocol>
*/
forceDetectProtocolForHost(hostname: string): Promise<string>;
/**
* Test if a protocol is supported for a given URL
* @param baseUrl Base URL to test (e.g., "https://example.com")
* @returns True if the protocol is supported
*/
private isProtocolSupported;
/**
* Get current branch name
*/
getCurrentBranch(): string;
/**
* Get target branch for merge request (default branch or fallback)
* @returns Target branch name
*/
getTargetBranch(): string;
/**
* Get current commit hash
*/
getCurrentCommit(): string;
/**
* Get all remote branches from the remote repository
* @param remoteName Remote name (optional, uses default remote if not provided)
* @returns Array of remote branch names (without remote prefix)
*/
getRemoteBranches(remoteName?: string): string[];
/**
* Check if a remote branch exists
* @param branchName Branch name to check (without remote prefix, e.g., 'main')
* @param remoteName Remote name (optional, uses default remote if not provided)
* @returns True if branch exists, false otherwise
*/
hasRemoteBranch(branchName: string, remoteName?: string): boolean;
/**
* Get short commit hash
*/
getShortCommit(): string;
/**
* Check if repository has uncommitted changes
*/
hasUncommittedChanges(): boolean;
/**
* Check if repository has staged changes
*/
hasStagedChanges(): boolean;
/**
* Get git repository status for all files
* @returns Array of GitFileStatus objects representing file changes
*/
status(): GitFileStatus[];
/**
* Parse a single git status line
* @param line Git status output line (format: "XY filename")
* @returns GitFileStatus object or null if invalid line
*/
private parseStatusLine;
/**
* Get human readable description for git status codes
* @param indexStatus Index status character
* @param workTreeStatus Working tree status character
* @returns Human readable status description
*/
private getStatusDescription;
/**
* Display comprehensive Git repository information
*/
showGitInfo(): void;
/**
* Get the most likely parent branch of the current branch
* @returns Base branch name or null if not found or in detached HEAD
*/
getBaseBranch(): string | null;
/**
* Get merge-base commit hash between current branch and target branch
* @param otherBranch Target branch name
* @returns Merge-base commit hash or null if not found
*/
getMergeBase(otherBranch: string): string | null;
/**
* Get simplified branch graph visualization (similar to GitLens)
* @param limit Maximum number of commits to show (default: 20)
* @returns String representation of branch graph
*/
getBranchGraph(limit?: number): string;
static instance(): GitService;
}
//# sourceMappingURL=git-service.d.ts.map