mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add git info to ProjectInfoDialog
This commit is contained in:
2 files changed
+351
-10
No files matched your search
@@ -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<ProjectMetadata>({});
|
||||
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 */}
|
||||
<Separator />
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-2">
|
||||
<GitCommit className="h-4 w-4" />
|
||||
Git Repository
|
||||
</h3>
|
||||
|
||||
{gitStatus.isLoading ? (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-4 w-1/2" />
|
||||
<Skeleton className="h-4 w-2/3" />
|
||||
</div>
|
||||
) : !gitStatus.data?.isGitRepo ? (
|
||||
<div className="text-sm text-muted-foreground flex items-center gap-2">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
This project is not a Git repository
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{/* Repository Status */}
|
||||
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||
{/* Current Branch */}
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Branch:</span>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{gitStatus.data?.currentBranch || 'unknown'}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
{/* Uncommitted Changes */}
|
||||
<div className="flex items-center gap-2">
|
||||
{gitStatus.data?.hasUncommittedChanges ? (
|
||||
<>
|
||||
<AlertCircle className="h-4 w-4 text-orange-500" />
|
||||
<span className="text-muted-foreground">Status:</span>
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
{gitStatus.data.changedFiles.length} uncommitted changes
|
||||
</Badge>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<CheckCircle className="h-4 w-4 text-green-500" />
|
||||
<span className="text-muted-foreground">Status:</span>
|
||||
<Badge variant="secondary" className="text-xs bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400">
|
||||
Clean working tree
|
||||
</Badge>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Total Commits */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Hash className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Commits:</span>
|
||||
<span>{gitStatus.data?.totalCommits || 0}</span>
|
||||
</div>
|
||||
|
||||
{/* All Branches */}
|
||||
<div className="flex items-center gap-2">
|
||||
<GitMerge className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Branches:</span>
|
||||
<span>{gitStatus.data?.branches.length || 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Latest Commit */}
|
||||
{gitStatus.data?.latestCommit && (
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
Latest Commit
|
||||
</h4>
|
||||
<div className="bg-muted/30 rounded-md p-3 space-y-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<GitCommit className="h-4 w-4 text-muted-foreground mt-0.5" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm font-medium break-words">
|
||||
{gitStatus.data.latestCommit.message.split('\n')[0]}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground font-mono">
|
||||
{gitStatus.data.latestCommit.oid.substring(0, 7)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-xs text-muted-foreground">
|
||||
<div className="flex items-center gap-1">
|
||||
<User className="h-3 w-3" />
|
||||
{gitStatus.data.latestCommit.author.name}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{new Date(gitStatus.data.latestCommit.author.timestamp * 1000).toLocaleDateString()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Changed Files */}
|
||||
{gitStatus.data?.hasUncommittedChanges && gitStatus.data.changedFiles.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
Uncommitted Changes
|
||||
</h4>
|
||||
<div className="space-y-1 max-h-32 overflow-y-auto">
|
||||
{gitStatus.data.changedFiles.map((file, index) => (
|
||||
<div key={index} className="flex items-center gap-2 text-sm">
|
||||
{file.status === 'added' && <Plus className="h-3 w-3 text-green-500" />}
|
||||
{file.status === 'modified' && <Edit className="h-3 w-3 text-blue-500" />}
|
||||
{file.status === 'deleted' && <Minus className="h-3 w-3 text-red-500" />}
|
||||
{file.status === 'untracked' && <Eye className="h-3 w-3 text-orange-500" />}
|
||||
{file.status === 'staged' && <CheckCircle className="h-3 w-3 text-purple-500" />}
|
||||
<span className="text-muted-foreground capitalize">{file.status}:</span>
|
||||
<code className="text-xs bg-muted px-1 py-0.5 rounded font-mono">
|
||||
{file.filepath}
|
||||
</code>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Remotes */}
|
||||
{gitStatus.data?.remotes && gitStatus.data.remotes.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
Remote Repositories
|
||||
</h4>
|
||||
<div className="space-y-1">
|
||||
{gitStatus.data.remotes.map((remote, index) => (
|
||||
<div key={index} className="flex items-center gap-2 text-sm">
|
||||
<Globe className="h-3 w-3 text-muted-foreground" />
|
||||
<span className="text-muted-foreground font-medium">{remote.name}:</span>
|
||||
<code className="text-xs bg-muted px-1 py-0.5 rounded font-mono break-all">
|
||||
{remote.url}
|
||||
</code>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)}
|
||||
|
||||
+183
-9
@@ -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,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user