feat: coloring of version history

This commit is contained in:
2026-02-16 14:42:04 +01:00
parent 1cd7d4f6ef
commit 772c0cbb0e
6 changed files with 91 additions and 9 deletions

View File

@@ -104,12 +104,14 @@ export interface GitIgnoreEnsureResult {
export interface GitLfsPruneOptions {
dryRun?: boolean;
verifyRemote?: boolean;
recentCommitsToKeep?: number;
}
export interface GitLfsPruneResult {
success: boolean;
dryRun: boolean;
verifyRemote: boolean;
recentCommitsToKeep: number;
output?: string;
error?: string;
}
@@ -823,8 +825,32 @@ export class GitEngine {
const git = simpleGit(projectPath);
const verifyRemote = options.verifyRemote ?? true;
const dryRun = options.dryRun ?? false;
const recentCommitsToKeep = Math.max(0, options.recentCommitsToKeep ?? 2);
const args = ['lfs', 'prune'];
let recentCommitDays = 0;
if (recentCommitsToKeep > 0) {
const history = await git.log({ maxCount: recentCommitsToKeep });
if (history.all.length > 0) {
const oldestProtected = history.all[history.all.length - 1];
const oldestProtectedTimestamp = new Date(oldestProtected.date).getTime();
if (!Number.isNaN(oldestProtectedTimestamp)) {
const msPerDay = 24 * 60 * 60 * 1000;
const ageInDays = Math.ceil(Math.max(0, Date.now() - oldestProtectedTimestamp) / msPerDay);
recentCommitDays = ageInDays;
}
}
}
const args = [
'-c',
`lfs.fetchrecentcommitsdays=${recentCommitDays}`,
'-c',
'lfs.fetchrecentrefsdays=0',
'-c',
'lfs.pruneoffsetdays=0',
'lfs',
'prune',
];
if (verifyRemote) {
args.push('--verify-remote');
}
@@ -838,6 +864,7 @@ export class GitEngine {
success: true,
dryRun,
verifyRemote,
recentCommitsToKeep,
output,
};
} catch (error) {
@@ -846,6 +873,7 @@ export class GitEngine {
success: false,
dryRun,
verifyRemote,
recentCommitsToKeep,
error: message,
};
}

View File

@@ -19,7 +19,7 @@ export const electronAPI: ElectronAPI = {
push: (projectPath: string) => ipcRenderer.invoke('git:push', projectPath),
commitAll: (projectPath: string, message: string) => ipcRenderer.invoke('git:commitAll', projectPath, message),
ensureGitignore: (projectPath: string) => ipcRenderer.invoke('git:ensureGitignore', projectPath),
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean }) => ipcRenderer.invoke('git:pruneLfs', projectPath, options),
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean; recentCommitsToKeep?: number }) => ipcRenderer.invoke('git:pruneLfs', projectPath, options),
init: (projectPath: string, remoteUrl?: string) => {
if (remoteUrl) {
return ipcRenderer.invoke('git:init', projectPath, remoteUrl);

View File

@@ -305,6 +305,7 @@ export interface GitLfsPruneResult {
success: boolean;
dryRun: boolean;
verifyRemote: boolean;
recentCommitsToKeep: number;
output?: string;
error?: string;
}
@@ -399,7 +400,7 @@ export interface ElectronAPI {
push: (projectPath: string) => Promise<GitActionResult>;
commitAll: (projectPath: string, message: string) => Promise<GitActionResult>;
ensureGitignore: (projectPath: string) => Promise<GitIgnoreEnsureResult>;
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean }) => Promise<GitLfsPruneResult>;
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean; recentCommitsToKeep?: number }) => Promise<GitLfsPruneResult>;
init: (projectPath: string, remoteUrl?: string) => Promise<GitInitResult>;
onInitProgress: (callback: (progress: GitInitProgress) => void) => () => void;
};

View File

@@ -220,6 +220,7 @@ export const GitSidebar: React.FC = () => {
: await window.electronAPI.git.pruneLfs(effectiveProjectPath, {
dryRun: false,
verifyRemote: true,
recentCommitsToKeep: 2,
});
if (!result.success) {
setError(result.error || `Failed to ${action}.`);