feat: implement default Git identity management and local identity check
This commit is contained in:
@@ -294,6 +294,7 @@ export interface GitAPI {
|
||||
getGitLog(directory: string, options?: GitLogOptions): Promise<GitLogResponse>;
|
||||
getCommitFiles(directory: string, hash: string): Promise<GitCommitFilesResponse>;
|
||||
getCurrentGitIdentity(directory: string): Promise<GitIdentitySummary | null>;
|
||||
hasLocalIdentity?(directory: string): Promise<boolean>;
|
||||
setGitIdentity(directory: string, profileId: string): Promise<{ success: boolean; profile: GitIdentityProfile }>;
|
||||
getGitIdentities(): Promise<GitIdentityProfile[]>;
|
||||
createGitIdentity(profile: GitIdentityProfile): Promise<GitIdentityProfile>;
|
||||
|
||||
@@ -56,6 +56,7 @@ export type DesktopSettings = {
|
||||
defaultModel?: string; // format: "provider/model"
|
||||
defaultVariant?: string;
|
||||
defaultAgent?: string;
|
||||
defaultGitIdentityId?: string; // ''/undefined = unset, 'global' or profile id
|
||||
autoCreateWorktree?: boolean;
|
||||
queueModeEnabled?: boolean;
|
||||
commitMessageModel?: string; // format: "provider/model"
|
||||
|
||||
@@ -239,6 +239,12 @@ export async function getCurrentGitIdentity(directory: string): Promise<import('
|
||||
return gitHttp.getCurrentGitIdentity(directory);
|
||||
}
|
||||
|
||||
export async function hasLocalIdentity(directory: string): Promise<boolean> {
|
||||
const runtime = getRuntimeGit();
|
||||
if (runtime?.hasLocalIdentity) return runtime.hasLocalIdentity(directory);
|
||||
return gitHttp.hasLocalIdentity(directory);
|
||||
}
|
||||
|
||||
export async function setGitIdentity(
|
||||
directory: string,
|
||||
profileId: string
|
||||
|
||||
@@ -516,6 +516,18 @@ export async function getCurrentGitIdentity(directory: string): Promise<GitIdent
|
||||
};
|
||||
}
|
||||
|
||||
export async function hasLocalIdentity(directory: string): Promise<boolean> {
|
||||
if (!directory) {
|
||||
return false;
|
||||
}
|
||||
const response = await fetch(buildUrl(`${API_BASE}/has-local-identity`, directory));
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to check local identity: ${response.statusText}`);
|
||||
}
|
||||
const data = await response.json().catch(() => null);
|
||||
return data?.hasLocalIdentity === true;
|
||||
}
|
||||
|
||||
export async function getGlobalGitIdentity(): Promise<GitIdentitySummary | null> {
|
||||
const response = await fetch(buildUrl(`${API_BASE}/global-identity`, undefined));
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user