UNPKG

@supos-ce-platform/git-tools

Version:

Supos ce platform Git tools, supos, ce, platform, git tools

105 lines (100 loc) 3.25 kB
import { SimpleGit } from 'simple-git'; interface RepoConfig { name: string; url: string; type: 'gitee' | 'gitea'; token?: string; username?: string; password?: string; } interface RemoteMergeHistory { sourceRepo: string; sourceBranch: string; targetRepo: string; targetBranch: string; options: { showDiff?: boolean; conflictStrategy?: 'ours' | 'theirs'; push?: boolean; }; timestamp: number; } declare class ConfigManager { private configPath; private config; constructor(); private loadConfig; private saveConfig; addRepo(repo: RepoConfig): void; getRepo(name: string): RepoConfig | undefined; removeRepo(name: string): void; listRepos(): RepoConfig[]; /** * 保存远程合并历史记录 * @param history 远程合并历史记录 */ saveRemoteMergeHistory(history: RemoteMergeHistory): void; /** * 获取远程合并历史记录 * @returns 远程合并历史记录,如果不存在则返回undefined */ getRemoteMergeHistory(): RemoteMergeHistory | undefined; } declare class MultiRepoMerge { private configManager; private tempDir; constructor(); initRepo(config: RepoConfig): Promise<SimpleGit>; mergeCrossBranch(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string): Promise<void>; abortMerge(repo: string): Promise<void>; resolveConflicts(repo: string, strategy: 'ours' | 'theirs'): Promise<void>; /** * 合并两个远程分支 * 相比mergeCrossBranch,此方法更专注于远程分支合并,减少了本地分支操作 * @param sourceRepo 源仓库名称 * @param sourceBranch 源分支名称 * @param targetRepo 目标仓库名称 * @param targetBranch 目标分支名称 * @param options 合并选项 */ mergeRemoteBranches(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string, options?: { /** 是否在合并前显示差异 */ showDiff?: boolean; /** 合并冲突时的自动解决策略 */ conflictStrategy?: 'ours' | 'theirs'; /** 是否推送合并结果 */ push?: boolean; }): Promise<void>; /** * 检查远程仓库中是否存在指定分支 * @param remoteName 远程仓库名称 * @param branchName 分支名称 * @param git Git实例 */ private checkRemoteBranchExists; } declare class GitMergeTools { private git; constructor(workingDir: string); /** * 合并源分支到目标分支 * @param source 源分支名 * @param target 目标分支名 */ mergeBranch(source: string, target: string): Promise<void>; /** * 中止当前的合并操作 */ abortMerge(): Promise<void>; /** * 使用指定策略解决冲突 * @param strategy 解决策略:'ours' 使用我们的更改,'theirs' 使用他们的更改 */ resolveConflicts(strategy: 'ours' | 'theirs'): Promise<void>; /** * 获取合并状态 * @returns 是否处于合并状态 */ isMerging(): Promise<boolean>; } export { ConfigManager, GitMergeTools, MultiRepoMerge, type RepoConfig };