From a9400df4b927244df55eaa5bb274f44a08f34946 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 29 Aug 2025 15:20:52 -0500 Subject: [PATCH] Add git info to ProjectInfoDialog --- src/components/ProjectInfoDialog.tsx | 169 ++++++++++++++++++++++- src/hooks/useGitStatus.ts | 192 +++++++++++++++++++++++++-- 2 files changed, 351 insertions(+), 10 deletions(-) diff --git a/src/components/ProjectInfoDialog.tsx b/src/components/ProjectInfoDialog.tsx index 59c20854..33fdf923 100644 --- a/src/components/ProjectInfoDialog.tsx +++ b/src/components/ProjectInfoDialog.tsx @@ -1,6 +1,7 @@ import { useState, useEffect } from 'react'; import { type Project } from '@/lib/ProjectsManager'; import { useProjectsManager } from '@/hooks/useProjectsManager'; +import { useGitStatus } from '@/hooks/useGitStatus'; import { Dialog, DialogContent, @@ -10,7 +11,26 @@ import { } from '@/components/ui/dialog'; import { Badge } from '@/components/ui/badge'; import { Separator } from '@/components/ui/separator'; -import { Calendar, Folder, GitBranch, Package, FileText } from 'lucide-react'; +import { Skeleton } from '@/components/ui/skeleton'; +import { + Calendar, + Folder, + GitBranch, + Package, + FileText, + GitCommit, + GitMerge, + Globe, + Clock, + User, + Hash, + AlertCircle, + CheckCircle, + Plus, + Minus, + Edit, + Eye +} from 'lucide-react'; interface ProjectInfoDialogProps { project: Project; @@ -29,6 +49,7 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi const [metadata, setMetadata] = useState({}); const [isLoading, setIsLoading] = useState(false); const projectsManager = useProjectsManager(); + const gitStatus = useGitStatus(project.id); useEffect(() => { if (!open) return; @@ -183,6 +204,152 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi )} + {/* Git Status Information */} + +
+

+ + Git Repository +

+ + {gitStatus.isLoading ? ( +
+ + + +
+ ) : !gitStatus.data?.isGitRepo ? ( +
+ + This project is not a Git repository +
+ ) : ( +
+ {/* Repository Status */} +
+ {/* Current Branch */} +
+ + Branch: + + {gitStatus.data?.currentBranch || 'unknown'} + +
+ + {/* Uncommitted Changes */} +
+ {gitStatus.data?.hasUncommittedChanges ? ( + <> + + Status: + + {gitStatus.data.changedFiles.length} uncommitted changes + + + ) : ( + <> + + Status: + + Clean working tree + + + )} +
+ + {/* Total Commits */} +
+ + Commits: + {gitStatus.data?.totalCommits || 0} +
+ + {/* All Branches */} +
+ + Branches: + {gitStatus.data?.branches.length || 0} +
+
+ + {/* Latest Commit */} + {gitStatus.data?.latestCommit && ( +
+

+ Latest Commit +

+
+
+ +
+
+ {gitStatus.data.latestCommit.message.split('\n')[0]} +
+
+ {gitStatus.data.latestCommit.oid.substring(0, 7)} +
+
+
+
+
+ + {gitStatus.data.latestCommit.author.name} +
+
+ + {new Date(gitStatus.data.latestCommit.author.timestamp * 1000).toLocaleDateString()} +
+
+
+
+ )} + + {/* Changed Files */} + {gitStatus.data?.hasUncommittedChanges && gitStatus.data.changedFiles.length > 0 && ( +
+

+ Uncommitted Changes +

+
+ {gitStatus.data.changedFiles.map((file, index) => ( +
+ {file.status === 'added' && } + {file.status === 'modified' && } + {file.status === 'deleted' && } + {file.status === 'untracked' && } + {file.status === 'staged' && } + {file.status}: + + {file.filepath} + +
+ ))} +
+
+ )} + + {/* Remotes */} + {gitStatus.data?.remotes && gitStatus.data.remotes.length > 0 && ( +
+

+ Remote Repositories +

+
+ {gitStatus.data.remotes.map((remote, index) => ( +
+ + {remote.name}: + + {remote.url} + +
+ ))} +
+
+ )} +
+ )} +
)} diff --git a/src/hooks/useGitStatus.ts b/src/hooks/useGitStatus.ts index cb8f5227..a4cea527 100644 --- a/src/hooks/useGitStatus.ts +++ b/src/hooks/useGitStatus.ts @@ -2,10 +2,42 @@ import { useQuery } from '@tanstack/react-query'; import git from 'isomorphic-git'; import { useFS } from './useFS'; +interface GitFileChange { + filepath: string; + status: 'modified' | 'added' | 'deleted' | 'untracked' | 'staged'; +} + +interface GitCommit { + oid: string; + message: string; + author: { + name: string; + email: string; + timestamp: number; + }; + committer: { + name: string; + email: string; + timestamp: number; + }; +} + +interface GitRemote { + name: string; + url: string; +} + interface GitStatus { hasUncommittedChanges: boolean; - changedFiles: string[]; + changedFiles: GitFileChange[]; isGitRepo: boolean; + currentBranch: string | null; + latestCommit: GitCommit | null; + remotes: GitRemote[]; + totalCommits: number; + branches: string[]; + ahead: number; + behind: number; } export function useGitStatus(projectId: string | null) { @@ -19,6 +51,13 @@ export function useGitStatus(projectId: string | null) { hasUncommittedChanges: false, changedFiles: [], isGitRepo: false, + currentBranch: null, + latestCommit: null, + remotes: [], + totalCommits: 0, + branches: [], + ahead: 0, + behind: 0, }; } @@ -33,27 +72,155 @@ export function useGitStatus(projectId: string | null) { hasUncommittedChanges: false, changedFiles: [], isGitRepo: false, + currentBranch: null, + latestCommit: null, + remotes: [], + totalCommits: 0, + branches: [], + ahead: 0, + behind: 0, }; } + // Get current branch + let currentBranch: string | null = null; + try { + const branch = await git.currentBranch({ + fs, + dir: cwd, + fullname: false, + }); + currentBranch = branch || null; + } catch (error) { + console.warn('Could not get current branch:', error); + } + + // Get all branches + const branches: string[] = []; + try { + const allBranches = await git.listBranches({ + fs, + dir: cwd, + }); + branches.push(...allBranches); + } catch (error) { + console.warn('Could not list branches:', error); + } + + // Get latest commit + let latestCommit: GitCommit | null = null; + let totalCommits = 0; + try { + const commits = await git.log({ + fs, + dir: cwd, + depth: 1, + }); + + if (commits.length > 0) { + const commit = commits[0]; + latestCommit = { + oid: commit.oid, + message: commit.commit.message, + author: { + name: commit.commit.author.name, + email: commit.commit.author.email, + timestamp: commit.commit.author.timestamp, + }, + committer: { + name: commit.commit.committer.name, + email: commit.commit.committer.email, + timestamp: commit.commit.committer.timestamp, + }, + }; + } + + // Get total commit count + const allCommits = await git.log({ + fs, + dir: cwd, + }); + totalCommits = allCommits.length; + } catch (error) { + console.warn('Could not get commit history:', error); + } + + // Get remotes + const remotes: GitRemote[] = []; + try { + const remoteNames = await git.listRemotes({ + fs, + dir: cwd, + }); + + for (const remote of remoteNames) { + remotes.push({ + name: remote.remote, + url: remote.url, + }); + } + } catch (error) { + console.warn('Could not get remotes:', error); + } + // Get git status to see what files have changed const statusMatrix = await git.statusMatrix({ fs, dir: cwd, }); - // Filter for files that have changes (not committed) - const changedFiles = statusMatrix.filter(([_filepath, headStatus, workdirStatus, stageStatus]) => { - // File has changes if: - // - workdir differs from head (modified/new/deleted) - // - stage differs from workdir (unstaged changes) - return headStatus !== workdirStatus || workdirStatus !== stageStatus; - }); + // Parse file changes with more detailed status + const changedFiles: GitFileChange[] = []; + for (const [filepath, headStatus, workdirStatus, stageStatus] of statusMatrix) { + let status: GitFileChange['status']; + + if (headStatus === 0 && workdirStatus === 2 && stageStatus === 0) { + status = 'untracked'; + } else if (headStatus === 0 && workdirStatus === 2 && stageStatus === 2) { + status = 'added'; + } else if (headStatus === 1 && workdirStatus === 2 && stageStatus === 2) { + status = 'staged'; + } else if (headStatus === 1 && workdirStatus === 2 && stageStatus === 1) { + status = 'modified'; + } else if (headStatus === 1 && workdirStatus === 0 && stageStatus === 0) { + status = 'deleted'; + } else if (headStatus !== workdirStatus || workdirStatus !== stageStatus) { + status = 'modified'; + } else { + continue; // No changes + } + + changedFiles.push({ + filepath, + status, + }); + } + + // Calculate ahead/behind (simplified - would need remote tracking branch info) + const ahead = 0; + const behind = 0; + try { + // This is a simplified calculation - in a real implementation, + // you'd compare with the remote tracking branch + if (currentBranch && remotes.length > 0) { + // For now, we'll leave these as 0 since calculating ahead/behind + // requires more complex remote branch comparison + } + } catch (error) { + console.warn('Could not calculate ahead/behind:', error); + } return { hasUncommittedChanges: changedFiles.length > 0, - changedFiles: changedFiles.map(([filepath]) => filepath), + changedFiles, isGitRepo: true, + currentBranch, + latestCommit, + remotes, + totalCommits, + branches, + ahead, + behind, }; } catch (error) { console.error('Error checking git status:', error); @@ -61,6 +228,13 @@ export function useGitStatus(projectId: string | null) { hasUncommittedChanges: false, changedFiles: [], isGitRepo: false, + currentBranch: null, + latestCommit: null, + remotes: [], + totalCommits: 0, + branches: [], + ahead: 0, + behind: 0, }; } },