fix: type

This commit is contained in:
lin onetwo 2025-11-24 03:42:04 +08:00
parent 6ac75cd19c
commit c87d9570b2
4 changed files with 28 additions and 23 deletions

View file

@ -7,7 +7,7 @@ import { exec as gitExec } from 'dugite';
import * as fs from 'node:fs/promises'; import * as fs from 'node:fs/promises';
import * as path from 'node:path'; import * as path from 'node:path';
import { defaultGitInfo } from './defaultGitInfo'; import { defaultGitInfo } from './defaultGitInfo';
import type { IGitLogOptions, IGitLogResult } from './interface'; import type { GitFileStatus, IFileDiffResult, IGitLogOptions, IGitLogResult } from './interface';
/** /**
* Helper to create git environment variables for commit operations * Helper to create git environment variables for commit operations
@ -125,7 +125,7 @@ export async function getGitLog(repoPath: string, options: IGitLogOptions = {}):
* Handles both git status --porcelain (two-character codes like "M ", " D", "??") * Handles both git status --porcelain (two-character codes like "M ", " D", "??")
* and git diff-tree --name-status (single-character codes like "M", "D", "A") * and git diff-tree --name-status (single-character codes like "M", "D", "A")
*/ */
function parseGitStatusCode(statusCode: string): 'added' | 'modified' | 'deleted' | 'renamed' | 'copied' | 'untracked' | 'unknown' { function parseGitStatusCode(statusCode: string): GitFileStatus {
// Handle single-character status codes from diff-tree // Handle single-character status codes from diff-tree
if (statusCode.length === 1) { if (statusCode.length === 1) {
if (statusCode === 'A') return 'added'; if (statusCode === 'A') return 'added';
@ -508,7 +508,7 @@ function createBinaryDiffPlaceholder(filePath: string): string {
* Truncate diff output if it exceeds the limits * Truncate diff output if it exceeds the limits
*/ */
function truncateDiff(diff: string, maxLines: number, maxChars: number): import('./interface').IFileDiffResult { function truncateDiff(diff: string, maxLines: number, maxChars: number): IFileDiffResult {
let truncated = diff; let truncated = diff;
let isTruncated = false; let isTruncated = false;
@ -532,9 +532,9 @@ function truncateDiff(diff: string, maxLines: number, maxChars: number): import(
} }
/** /**
* Truncate content if it exceeds the limits * Truncate content output if it exceeds the limits
*/ */
function truncateContent(content: string, maxLines: number, maxChars: number): import('./interface').IFileDiffResult { function truncateContent(content: string, maxLines: number, maxChars: number): IFileDiffResult {
return truncateDiff(content, maxLines, maxChars); return truncateDiff(content, maxLines, maxChars);
} }

View file

@ -24,7 +24,18 @@ import { WindowNames } from '@services/windows/WindowProperties';
import { isWikiWorkspace, type IWorkspace } from '@services/workspaces/interface'; import { isWikiWorkspace, type IWorkspace } from '@services/workspaces/interface';
import * as gitOperations from './gitOperations'; import * as gitOperations from './gitOperations';
import type { GitWorker } from './gitWorker'; import type { GitWorker } from './gitWorker';
import type { ICommitAndSyncConfigs, IForcePullConfigs, IGitLogMessage, IGitLogOptions, IGitLogResult, IGitService, IGitStateChange, IGitUserInfos } from './interface'; import type {
ICommitAndSyncConfigs,
IFileDiffResult,
IFileWithStatus,
IForcePullConfigs,
IGitLogMessage,
IGitLogOptions,
IGitLogResult,
IGitService,
IGitStateChange,
IGitUserInfos,
} from './interface';
import { registerMenu } from './registerMenu'; import { registerMenu } from './registerMenu';
import { getErrorMessageI18NDict, translateMessage } from './translateMessage'; import { getErrorMessageI18NDict, translateMessage } from './translateMessage';
@ -359,15 +370,15 @@ export class Git implements IGitService {
return await gitOperations.getGitLog(wikiFolderPath, options); return await gitOperations.getGitLog(wikiFolderPath, options);
} }
public async getCommitFiles(wikiFolderPath: string, commitHash: string): Promise<string[]> { public async getCommitFiles(wikiFolderPath: string, commitHash: string): Promise<IFileWithStatus[]> {
return await gitOperations.getCommitFiles(wikiFolderPath, commitHash); return await gitOperations.getCommitFiles(wikiFolderPath, commitHash);
} }
public async getFileDiff(wikiFolderPath: string, commitHash: string, filePath: string, maxLines?: number, maxChars?: number): Promise<import('./interface').IFileDiffResult> { public async getFileDiff(wikiFolderPath: string, commitHash: string, filePath: string, maxLines?: number, maxChars?: number): Promise<IFileDiffResult> {
return await gitOperations.getFileDiff(wikiFolderPath, commitHash, filePath, maxLines, maxChars); return await gitOperations.getFileDiff(wikiFolderPath, commitHash, filePath, maxLines, maxChars);
} }
public async getFileContent(wikiFolderPath: string, commitHash: string, filePath: string, maxLines?: number, maxChars?: number): Promise<import('./interface').IFileDiffResult> { public async getFileContent(wikiFolderPath: string, commitHash: string, filePath: string, maxLines?: number, maxChars?: number): Promise<IFileDiffResult> {
return await gitOperations.getFileContent(wikiFolderPath, commitHash, filePath, maxLines, maxChars); return await gitOperations.getFileContent(wikiFolderPath, commitHash, filePath, maxLines, maxChars);
} }

View file

@ -1,6 +1,8 @@
import type { Theme } from '@mui/material/styles'; import type { Theme } from '@mui/material/styles';
import type { GitFileStatus } from '../../services/git/interface';
export type GitFileStatus = 'added' | 'modified' | 'deleted' | 'renamed' | 'copied' | 'untracked' | 'unknown'; // Re-export for convenience
export type { GitFileStatus };
/** /**
* Get styled CSS for file status badge/chip based on the status and theme * Get styled CSS for file status badge/chip based on the status and theme

View file

@ -1,3 +1,5 @@
import type { GitFileStatus, IFileWithStatus } from '../../services/git/interface';
/** /**
* Represents the author or committer of a commit. * Represents the author or committer of a commit.
*/ */
@ -12,18 +14,8 @@ export interface CommitAuthor {
name: string; name: string;
} }
/** // Re-export for convenience
* File status in git export type { GitFileStatus, IFileWithStatus };
*/
export type GitFileStatus = 'added' | 'modified' | 'deleted' | 'renamed' | 'copied' | 'untracked' | 'unknown';
/**
* File with status information
*/
export interface FileWithStatus {
path: string;
status: GitFileStatus;
}
/** /**
* Represents a single entry in the git log. * Represents a single entry in the git log.
@ -60,5 +52,5 @@ export interface GitLogEntry {
/** /**
* Array of files with status changed in this commit. * Array of files with status changed in this commit.
*/ */
files?: FileWithStatus[]; files?: IFileWithStatus[];
} }