mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Git Source Control Integration (#74)
* feat(source-control): add commits and file management components - Introduced `CommitsTab` for displaying commit history with relative time formatting. - Added `GitFlatFileItem` and `GitFlatFileList` for managing file statuses in the source control panel. - Implemented `SourceControlPanel` to encapsulate source control functionalities including changes, commits, and branches. - Enhanced `useGit` hook to manage git operations such as fetch, pull, push, commit, stage, and unstage files with appropriate error handling and toast notifications. - Updated `RepoDetail` to integrate the new source control panel and provide a user interface for source control actions. - Defined `GitCommit` type for better type safety in commit-related operations. * refactor: streamline error handling in Git operations and update error imports * feat: enhance Git services and ESLint configuration for improved functionality * refactor: update method signatures for consistency and clarity in Git services * feat: refactor git services and improve error handling - Remove unused imports and clean up code in repos.ts and git-operations.ts. - Simplify error handling in repo.ts by enforcing message property in ErrorWithMessage interface. - Update GitPushService to remove unnecessary database parameter in methods. - Enhance executeCommand function to better handle command execution results. - Update tests to use mocked functions for better isolation and clarity. - Add specific ESLint rules for test files to accommodate common testing patterns. - Introduce tsconfig.test.json for better TypeScript configuration in tests. - Update vitest.config.ts to use the new test TypeScript configuration. * refactor: remove esbuild configuration from Vitest setup * feat: enhance Source Control Panel with branch management and integrate into RepoDetail and SessionDetail pages * feat: implement Git authentication service and refactor related services - Add GitAuthService to handle Git environment setup with credentials. - Refactor GitBranchService, GitCommitService, GitFetchPullService, GitPushService, GitStatusService, and GitLogService to utilize the new GitAuthService. - Remove GitCommandUtils and related error handling for Git operations. - Delete git-operations.ts and associated tests as functionality is now integrated into other services. - Update TypeScript configuration to enable composite projects for better build management. * feat: refactor Git services to improve structure and update imports * refactor: simplify error utility functions and update test cases for Git services * feat: refactor GitAuthService and update related tests for improved credential handling * feat: implement GitDiffService and related endpoints for file diff functionality * feat: add emitDeclarationOnly option to TypeScript configuration files * feat: enhance GitLogService to fetch remote branches and improve error handling in repo commands * feat: update Git command execution to remove fallback and enhance environment variable handling * feat: add repository authentication tracking - Add `requires_auth` column to repos table - Implement auth check in GitAuthService - Update cloneRepo to detect public/private repos - Add test coverage for auth-related functionality - Improve UI styling for auth-related indicators * feat(git): implement interactive Git authentication with askpass - Add GitAskpassService to handle credential requests from Git - Implement askpass script that communicates with backend - Update GitAuthService to use askpass instead of direct credential injection - Add new endpoint for branch listing and status - Improve branch name handling in GitBranchService - Enhance error handling in GitDiffService for untracked files - Add upstream branch checking and setup in GitFetchPullService - Update UI components for better visual consistency - Fix various minor UI styling issues * feat(git): enhance Git authentication with improved askpass support - Update askpass endpoint to handle hostname parameter and return full credential object - Replace `createNoPromptGitEnv` with `createSilentGitEnv` for better VSCode compatibility - Add compiled Node.js askpass script for broader compatibility - Enhance GitBranchService to return detailed branch information with upstream tracking - Improve branch listing UI with better sorting and display - Update GitAuthService to use askpass for all operations with proper credential handling - Fix various UI styling issues in diff view and source control panel - Update test mocks to use new silent environment function - Add proper error handling and credential caching in GitAskpassService * feat(git-auth): implement IPC-based Git authentication system - Add new IPC server infrastructure for handling Git credential requests - Implement AskpassHandler to manage Git authentication through IPC - Replace previous HTTP-based askpass system with local IPC communication - Remove deprecated GitAskpassService and related HTTP endpoints - Update GitAuthService to use IPC-based authentication flow - Add new shell scripts for Git askpass integration (askpass.sh, askpass-main.js) - Remove database column 'requires_auth' as it's no longer needed - Update all Git service classes to use new authentication approach - Improve error handling and credential caching - Add proper cleanup for IPC server on shutdown * fix(frontend): correct GitBranch type usage in BranchesTab and BranchSwitcher * fix(ipc): handle empty responses and add logging for askpass handler - Handle empty response bodies in askpass-main.ts to prevent JSON parse errors - Add logging to IPC server for debugging request/response issues - Add logging to AskpassHandler for credential lookup visibility * fix(ipc): return empty credentials for silent fetches instead of failing Silent fetch operations (used when fetching commit history on repo open) should return empty credentials gracefully rather than failing, allowing git to proceed without credentials for public repos or cached credentials. * chore(ipc): add detailed logging for debugging askpass requests - Log handler registration and lookup paths - Log incoming request details - Log handler response results * chore(askpass): add comprehensive debugging to trace IPC communication - Add detailed stderr logging to askpass-main.ts for all steps - Log environment variables and paths at initialization - Log IPC connection attempts and responses - Log JSON parsing results This will help trace where the IPC communication fails. * chore(debug): add comprehensive logging to trace git environment and IPC requests - Log GIT_ASKPASS, VSCODE_GIT_IPC_HANDLE, GIT_TERMINAL_PROMPT env vars when executing git - Log all incoming IPC requests with URL and body - Log handler registration status * Integrate GitAuthService throughout repo operations - Add GitAuthService parameter to all repo service functions - Replace direct git env creation with GitAuthService.getGitEnvironment() - Update route handlers to pass GitAuthService to service calls - Remove createSilentGitEnv utility in favor of centralized auth - Ensure consistent git authentication across all operations * refactor: consolidate git services and remove duplicate fetch service - Remove GitFetchService and consolidate into GitFetchPullService - Clean up duplicate git authentication logic across services - Simplify repo service by removing redundant environment handling - Update tests to reflect consolidated service structure - Remove unused imports and streamline API endpoints - Reduce codebase complexity by eliminating service duplication * refactor: clean up unnecessary config changes and improve git API types * feat(git): add GitCommit interface and fix push mutation * feat(git): fix source control panel issues - Fix unstaged file diff showing all changes instead of working directory only - Remove auto-refresh (10s) to reduce git command spam - Add reset/revert mutation for unpushed local commits - Fix branch creation/switching to update database - Add unpushed commit detection and visual indicator in commits tab - Handle no-upstream branch status gracefully * fix(git): improve branch listing and remove regex parsing issue - Fix branch name parsing to use full name instead of regex capturing only first word - Add refresh button for branches - Show remote branches with Globe icon and make them non-clickable - Add 'local' label for branches without upstream tracking - Handle remotes/ prefix properly in branch detection * fix(git): remove duplicate refresh button * fix(git): properly extract branch name from git output - Extract branch name before whitespace/bracket in git branch -vv -a output - When clicking remote branch, checkout local tracking branch instead of remote reference * fix(git): remove duplicate refresh button from branches tab * fix: improve source control panel mobile layout - Set full height on mobile for better screen utilization - Add larger centered close button on mobile - Hide default close button when custom one is shown on mobile * Remove git credential test feature The test credential button in settings was broken because it tried to test authentication against just the host URL (e.g., https://github.com/) instead of a repository path. Since git credentials are already handled correctly through the askpass mechanism when cloning repositories, the test button was redundant and has been removed. Changes: - Remove /test-credential endpoint from settings routes - Remove testGitCredential API from frontend - Remove TestCredentialRequest/Response types - Remove test button and related state from GitSettings component * fix: resolve Copilot review issues - Remove duplicate GitCommit interface definition - Fix CSS typos: bg-linear-to-br -> bg-gradient-to-br - Fix typo: /sessflex-shrink-0 -> flex-shrink-0 - Add *.test.js to .gitignore and remove compiled test files - Fix missing closing brace in useGit.test.tsx - Remove unused maskToken function * fix(git): correct ahead/behind count order and add renamed file path parsing - Fix git rev-list output parsing: ahead comes first, behind second - Add oldPath extraction for renamed (R) and copied (C) files in status - Refactor git service tests to use consistent mocking patterns - Add missing Database and SettingsService mocks to prevent test failures --------- Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
1 parent
524ce018dc
commit
e91c54ba20
64 files changed
+6214
-1915
No files matched your search
@@ -0,0 +1,211 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { listBranches, switchBranch, GitAuthError } from '@/api/repos'
|
||||
import { useGitStatus } from '@/api/git'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Loader2, GitBranch, Check, Plus, AlertCircle, ArrowUp, ArrowDown, Globe } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
|
||||
interface BranchesTabProps {
|
||||
repoId: number
|
||||
currentBranch: string
|
||||
}
|
||||
|
||||
export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [newBranchName, setNewBranchName] = useState('')
|
||||
const [isCreating, setIsCreating] = useState(false)
|
||||
const git = useGit(repoId)
|
||||
|
||||
const { data: status } = useGitStatus(repoId)
|
||||
|
||||
const { data: branches, isLoading, error, refetch } = useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: (updatedRepo) => {
|
||||
queryClient.setQueryData(['repo', repoId], updatedRepo)
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['gitStatus', repoId] })
|
||||
refetch()
|
||||
showToast.success(`Switched to branch: ${updatedRepo.currentBranch}`)
|
||||
},
|
||||
onError: (error) => {
|
||||
if (error instanceof GitAuthError) {
|
||||
showToast.error('Authentication failed. Please update your Git token in Settings.')
|
||||
} else {
|
||||
showToast.error(error.message || 'Failed to switch branch')
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const handleCreateBranch = async () => {
|
||||
if (!newBranchName.trim()) return
|
||||
|
||||
try {
|
||||
await git.createBranch.mutateAsync(newBranchName.trim())
|
||||
setNewBranchName('')
|
||||
setIsCreating(false)
|
||||
refetch()
|
||||
} catch {
|
||||
// Error handled by mutation
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<AlertCircle className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">Failed to load branches</p>
|
||||
<p className="text-xs mt-1">{error.message}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const activeBranch = branches?.branches?.find(b => b.current)?.name || currentBranch
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="p-3 border-b border-border space-y-3 flex-shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="w-4 h-4 text-muted-foreground" />
|
||||
<span className="text-sm font-medium">Current: {activeBranch}</span>
|
||||
{status && (status.ahead > 0 || status.behind > 0) && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
{status.ahead > 0 && (
|
||||
<span className="flex items-center gap-0.5">
|
||||
<ArrowUp className="w-3 h-3" />{status.ahead}
|
||||
</span>
|
||||
)}
|
||||
{status.behind > 0 && (
|
||||
<span className="flex items-center gap-0.5">
|
||||
<ArrowDown className="w-3 h-3" />{status.behind}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isCreating ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="New branch name..."
|
||||
value={newBranchName}
|
||||
onChange={(e) => setNewBranchName(e.target.value)}
|
||||
className="h-8 text-sm"
|
||||
autoFocus
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') handleCreateBranch()
|
||||
if (e.key === 'Escape') {
|
||||
setIsCreating(false)
|
||||
setNewBranchName('')
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
className="h-8"
|
||||
onClick={handleCreateBranch}
|
||||
disabled={!newBranchName.trim() || git.createBranch.isPending}
|
||||
>
|
||||
{git.createBranch.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
'Create'
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8"
|
||||
onClick={() => {
|
||||
setIsCreating(false)
|
||||
setNewBranchName('')
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="w-full h-8"
|
||||
onClick={() => setIsCreating(true)}
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Create New Branch
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{branches?.branches && branches.branches.length > 0 ? (
|
||||
<div className="py-1">
|
||||
{branches.branches.map((branch) => {
|
||||
const isCurrent = branch.name === activeBranch || branch.name === `remotes/${activeBranch}`
|
||||
const isRemote = branch.type === 'remote'
|
||||
|
||||
const handleClick = () => {
|
||||
if (isCurrent) return
|
||||
|
||||
let branchToCheckout = branch.name
|
||||
if (isRemote) {
|
||||
branchToCheckout = branch.name.replace(/^remotes\/[^/]+\//, '')
|
||||
}
|
||||
switchBranchMutation.mutate(branchToCheckout)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
key={branch.name}
|
||||
className={cn(
|
||||
'flex items-center gap-2 px-3 py-2 w-full text-left hover:bg-accent/50 transition-colors',
|
||||
isCurrent && 'bg-accent'
|
||||
)}
|
||||
onClick={handleClick}
|
||||
disabled={isCurrent || switchBranchMutation.isPending}
|
||||
>
|
||||
{isRemote ? (
|
||||
<Globe className="w-4 h-4 text-blue-500" />
|
||||
) : (
|
||||
<GitBranch className={cn('w-4 h-4', isCurrent ? GIT_UI_COLORS.current : 'text-muted-foreground')} />
|
||||
)}
|
||||
<span className="flex-1 text-sm truncate">{branch.name}</span>
|
||||
{branch.type === 'local' && !branch.upstream && (
|
||||
<span className="text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground">local</span>
|
||||
)}
|
||||
{isCurrent && <Check className={`w-4 h-4 ${GIT_UI_COLORS.current}`} />}
|
||||
{switchBranchMutation.isPending && switchBranchMutation.variables === branch.name && (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<GitBranch className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">No branches found</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
import { useState } from 'react'
|
||||
import { useGitStatus, getApiErrorMessage } from '@/api/git'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { GitFlatFileList } from './GitFlatFileList'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||
import { FileDiffView } from '@/components/file-browser/FileDiffView'
|
||||
import { Loader2, GitCommit, FileText, AlertCircle, X } from 'lucide-react'
|
||||
|
||||
interface ChangesTabProps {
|
||||
repoId: number
|
||||
onFileSelect: (path: string, staged: boolean) => void
|
||||
selectedFile?: {path: string, staged: boolean}
|
||||
isMobile: boolean
|
||||
}
|
||||
|
||||
export function ChangesTab({ repoId, onFileSelect, selectedFile, isMobile }: ChangesTabProps) {
|
||||
const { data: status, isLoading, error } = useGitStatus(repoId)
|
||||
const git = useGit(repoId)
|
||||
const [commitMessage, setCommitMessage] = useState('')
|
||||
const [apiError, setApiError] = useState<string | null>(null)
|
||||
|
||||
const stagedFiles = status?.files.filter(f => f.staged) || []
|
||||
const unstagedFiles = status?.files.filter(f => !f.staged) || []
|
||||
const canCommit = commitMessage.trim() && stagedFiles.length > 0 && !git.commit.isPending
|
||||
|
||||
const handleGitAction = async (action: () => Promise<unknown>) => {
|
||||
try {
|
||||
setApiError(null)
|
||||
await action()
|
||||
} catch (error: unknown) {
|
||||
const message = getApiErrorMessage(error)
|
||||
setApiError(message)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStage = (paths: string[]) => {
|
||||
handleGitAction(() => git.stageFiles.mutateAsync(paths))
|
||||
}
|
||||
|
||||
const handleUnstage = (paths: string[]) => {
|
||||
handleGitAction(() => git.unstageFiles.mutateAsync(paths))
|
||||
}
|
||||
|
||||
const handleCommit = () => {
|
||||
handleGitAction(async () => {
|
||||
await git.commit.mutateAsync({ message: commitMessage.trim() })
|
||||
setCommitMessage('')
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<AlertCircle className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">Failed to load git status</p>
|
||||
<p className="text-xs mt-1">{error.message}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!status) return null
|
||||
|
||||
if (isMobile && selectedFile) {
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{apiError && (
|
||||
<div className="mx-3 mt-3 p-2 rounded border bg-destructive/10 border-destructive/20 flex items-center gap-2">
|
||||
<AlertCircle className="w-4 h-4 text-destructive flex-shrink-0" />
|
||||
<span className="text-sm text-destructive flex-1">{apiError}</span>
|
||||
<Button variant="ghost" size="sm" className="h-6 w-6 p-0" onClick={() => setApiError(null)}>
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Tabs defaultValue="files" className="flex flex-col h-full">
|
||||
<TabsList className="flex-shrink-0">
|
||||
<TabsTrigger value="files">Files ({stagedFiles.length + unstagedFiles.length})</TabsTrigger>
|
||||
<TabsTrigger value="diff">{selectedFile.path.split('/').pop() || selectedFile.path}</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="files" className="flex-1 overflow-hidden mt-0">
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="flex-1 overflow-y-auto p-3 space-y-4">
|
||||
{status.hasChanges ? (
|
||||
<>
|
||||
{stagedFiles.length > 0 && (
|
||||
<GitFlatFileList
|
||||
files={status.files}
|
||||
staged={true}
|
||||
onSelect={onFileSelect}
|
||||
onUnstage={handleUnstage}
|
||||
selectedFile={selectedFile?.path}
|
||||
/>
|
||||
)}
|
||||
|
||||
{unstagedFiles.length > 0 && (
|
||||
<GitFlatFileList
|
||||
files={status.files}
|
||||
staged={false}
|
||||
onSelect={onFileSelect}
|
||||
onStage={handleStage}
|
||||
selectedFile={selectedFile?.path}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<FileText className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">No uncommitted changes</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{status.hasChanges && (
|
||||
<div className="p-3 border-t border-border space-y-2 flex-shrink-0">
|
||||
<Textarea
|
||||
placeholder="Commit message..."
|
||||
value={commitMessage}
|
||||
onChange={(e) => setCommitMessage(e.target.value)}
|
||||
className="min-h-[80px] text-sm resize-none"
|
||||
onKeyDown={(e) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && canCommit) {
|
||||
handleCommit()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCommit}
|
||||
disabled={!canCommit}
|
||||
className="w-full h-9"
|
||||
>
|
||||
{git.commit.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin mr-2" />
|
||||
) : (
|
||||
<GitCommit className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
Commit {stagedFiles.length > 0 && `(${stagedFiles.length} staged)`}
|
||||
</Button>
|
||||
<p className="text-[10px] text-muted-foreground text-center">
|
||||
{navigator.platform.includes('Mac') ? '⌘' : 'Ctrl'}+Enter to commit
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="diff" className="flex-1 overflow-hidden mt-0">
|
||||
<FileDiffView repoId={repoId} filePath={selectedFile.path} includeStaged={selectedFile.staged} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{apiError && (
|
||||
<div className="mx-3 mt-3 p-2 rounded border bg-destructive/10 border-destructive/20 flex items-center gap-2">
|
||||
<AlertCircle className="w-4 h-4 text-destructive flex-shrink-0" />
|
||||
<span className="text-sm text-destructive flex-1">{apiError}</span>
|
||||
<Button variant="ghost" size="sm" className="h-6 w-6 p-0" onClick={() => setApiError(null)}>
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-3 space-y-4">
|
||||
{status.hasChanges ? (
|
||||
<>
|
||||
{stagedFiles.length > 0 && (
|
||||
<GitFlatFileList
|
||||
files={status.files}
|
||||
staged={true}
|
||||
onSelect={onFileSelect}
|
||||
onUnstage={handleUnstage}
|
||||
selectedFile={selectedFile?.path}
|
||||
/>
|
||||
)}
|
||||
|
||||
{unstagedFiles.length > 0 && (
|
||||
<GitFlatFileList
|
||||
files={status.files}
|
||||
staged={false}
|
||||
onSelect={onFileSelect}
|
||||
onStage={handleStage}
|
||||
selectedFile={selectedFile?.path}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<FileText className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">No uncommitted changes</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{status.hasChanges && (
|
||||
<div className="p-3 border-t border-border space-y-2 flex-shrink-0">
|
||||
<Textarea
|
||||
placeholder="Commit message..."
|
||||
value={commitMessage}
|
||||
onChange={(e) => setCommitMessage(e.target.value)}
|
||||
className="min-h-[80px] text-sm resize-none"
|
||||
onKeyDown={(e) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && canCommit) {
|
||||
handleCommit()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCommit}
|
||||
disabled={!canCommit}
|
||||
className="w-full h-9"
|
||||
>
|
||||
{git.commit.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin mr-2" />
|
||||
) : (
|
||||
<GitCommit className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
Commit {stagedFiles.length > 0 && `(${stagedFiles.length} staged)`}
|
||||
</Button>
|
||||
<p className="text-[10px] text-muted-foreground text-center">
|
||||
{navigator.platform.includes('Mac') ? '⌘' : 'Ctrl'}+Enter to commit
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { useGitLog } from '@/api/git'
|
||||
import { Loader2, GitCommit, AlertCircle, ArrowUp } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
|
||||
interface CommitsTabProps {
|
||||
repoId: number
|
||||
onSelectCommit?: (hash: string) => void
|
||||
}
|
||||
|
||||
function formatRelativeTime(dateString: string): string {
|
||||
const date = new Date(dateString)
|
||||
const now = new Date()
|
||||
const diffMs = now.getTime() - date.getTime()
|
||||
const diffSeconds = Math.floor(diffMs / 1000)
|
||||
const diffMinutes = Math.floor(diffSeconds / 60)
|
||||
const diffHours = Math.floor(diffMinutes / 60)
|
||||
const diffDays = Math.floor(diffHours / 24)
|
||||
const diffWeeks = Math.floor(diffDays / 7)
|
||||
const diffMonths = Math.floor(diffDays / 30)
|
||||
|
||||
if (diffSeconds < 60) return 'just now'
|
||||
if (diffMinutes < 60) return `${diffMinutes}m ago`
|
||||
if (diffHours < 24) return `${diffHours}h ago`
|
||||
if (diffDays < 7) return `${diffDays}d ago`
|
||||
if (diffWeeks < 4) return `${diffWeeks}w ago`
|
||||
return `${diffMonths}mo ago`
|
||||
}
|
||||
|
||||
export function CommitsTab({ repoId, onSelectCommit }: CommitsTabProps) {
|
||||
const { data, isLoading, error } = useGitLog(repoId, 50)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<AlertCircle className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">Failed to load commits</p>
|
||||
<p className="text-xs mt-1">{error.message}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data?.commits || data.commits.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-12 text-muted-foreground">
|
||||
<GitCommit className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">No commits found</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full overflow-y-auto">
|
||||
{data.commits.map((commit) => (
|
||||
<button
|
||||
key={commit.hash}
|
||||
className="flex items-start gap-3 px-3 py-2 text-left hover:bg-accent/50 transition-colors border-b border-border last:border-0"
|
||||
onClick={() => onSelectCommit?.(commit.hash)}
|
||||
>
|
||||
<div className="flex-shrink-0 w-8 h-8 rounded-full bg-accent flex items-center justify-center mt-0.5">
|
||||
<GitCommit className="w-4 h-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{commit.message}</p>
|
||||
<div className="flex items-center gap-2 mt-1 text-xs text-muted-foreground">
|
||||
<span className="font-mono">{commit.hash.substring(0, 7)}</span>
|
||||
<span>·</span>
|
||||
<span className="truncate">{commit.authorName}</span>
|
||||
<span>·</span>
|
||||
<span className="flex-shrink-0">{formatRelativeTime(commit.date)}</span>
|
||||
{commit.unpushed && (
|
||||
<span className={cn('flex items-center gap-0.5 px-1 rounded', GIT_UI_COLORS.unpushed)}>
|
||||
<ArrowUp className="w-3 h-3" />
|
||||
Local
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Plus, Minus, FileText, FilePlus, FileX, FileSearch, CircleDot } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { GitFileStatus } from '@/types/git'
|
||||
import { GIT_STATUS_COLORS, GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
|
||||
interface GitFlatFileItemProps {
|
||||
file: GitFileStatus
|
||||
isSelected: boolean
|
||||
onSelect: (path: string, staged: boolean) => void
|
||||
onStage?: (path: string) => void
|
||||
onUnstage?: (path: string) => void
|
||||
}
|
||||
|
||||
const statusIcons = {
|
||||
modified: FileSearch,
|
||||
added: FilePlus,
|
||||
deleted: FileX,
|
||||
renamed: FileSearch,
|
||||
untracked: CircleDot,
|
||||
copied: FilePlus,
|
||||
}
|
||||
|
||||
export function GitFlatFileItem({ file, isSelected, onSelect, onStage, onUnstage }: GitFlatFileItemProps) {
|
||||
const StatusIcon = statusIcons[file.status] || FileText
|
||||
const statusColor = GIT_STATUS_COLORS[file.status] || 'text-muted-foreground'
|
||||
|
||||
const fileName = file.path.split('/').pop() || file.path
|
||||
const dirPath = file.path.includes('/') ? file.path.substring(0, file.path.lastIndexOf('/')) : ''
|
||||
|
||||
const handleAction = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (file.staged && onUnstage) {
|
||||
onUnstage(file.path)
|
||||
} else if (!file.staged && onStage) {
|
||||
onStage(file.path)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'group flex items-center gap-2 px-2 py-1 rounded cursor-pointer hover:bg-accent transition-colors',
|
||||
isSelected && 'bg-accent'
|
||||
)}
|
||||
onClick={() => onSelect(file.path, file.staged)}
|
||||
>
|
||||
<StatusIcon className={cn('w-4 h-4 flex-shrink-0', statusColor)} />
|
||||
<div className="flex-1 min-w-0 flex items-center gap-1">
|
||||
<span className="text-sm truncate">{fileName}</span>
|
||||
{dirPath && (
|
||||
<span className="text-xs text-muted-foreground truncate">
|
||||
{dirPath}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{file.staged && (
|
||||
<span className={cn('text-[10px] px-1.5 py-0.5 rounded flex-shrink-0', GIT_UI_COLORS.stagedBadge)}>
|
||||
staged
|
||||
</span>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 w-6 p-0 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"
|
||||
onClick={handleAction}
|
||||
>
|
||||
{file.staged ? (
|
||||
<Minus className={cn('w-3 h-3', GIT_UI_COLORS.unstage)} />
|
||||
) : (
|
||||
<Plus className={cn('w-3 h-3', GIT_UI_COLORS.stage)} />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { ChevronDown, ChevronRight, Plus, Minus } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { GitFlatFileItem } from './GitFlatFileItem'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { GitFileStatus, GitFileStatusType } from '@/types/git'
|
||||
import { GIT_STATUS_COLORS, GIT_STATUS_LABELS } from '@/lib/git-status-styles'
|
||||
|
||||
interface GitFlatFileListProps {
|
||||
files: GitFileStatus[]
|
||||
staged: boolean
|
||||
onSelect: (path: string, staged: boolean) => void
|
||||
onStage?: (paths: string[]) => void
|
||||
onUnstage?: (paths: string[]) => void
|
||||
selectedFile?: string
|
||||
}
|
||||
|
||||
interface GroupedFiles {
|
||||
status: GitFileStatusType
|
||||
files: GitFileStatus[]
|
||||
}
|
||||
|
||||
const statusOrder: GitFileStatusType[] = ['modified', 'added', 'deleted', 'renamed', 'copied', 'untracked']
|
||||
|
||||
export function GitFlatFileList({
|
||||
files,
|
||||
staged,
|
||||
onSelect,
|
||||
onStage,
|
||||
onUnstage,
|
||||
selectedFile,
|
||||
}: GitFlatFileListProps) {
|
||||
const [collapsedGroups, setCollapsedGroups] = useState<Set<GitFileStatusType>>(new Set())
|
||||
|
||||
const filteredFiles = useMemo(() => {
|
||||
return files.filter(f => f.staged === staged)
|
||||
}, [files, staged])
|
||||
|
||||
const groupedFiles = useMemo(() => {
|
||||
const groups: GroupedFiles[] = []
|
||||
|
||||
for (const status of statusOrder) {
|
||||
const statusFiles = filteredFiles.filter(f => f.status === status)
|
||||
if (statusFiles.length > 0) {
|
||||
groups.push({ status, files: statusFiles })
|
||||
}
|
||||
}
|
||||
|
||||
return groups
|
||||
}, [filteredFiles])
|
||||
|
||||
const toggleGroup = (status: GitFileStatusType) => {
|
||||
setCollapsedGroups(prev => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(status)) {
|
||||
next.delete(status)
|
||||
} else {
|
||||
next.add(status)
|
||||
}
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const handleStageFile = (path: string) => {
|
||||
onStage?.([path])
|
||||
}
|
||||
|
||||
const handleUnstageFile = (path: string) => {
|
||||
onUnstage?.([path])
|
||||
}
|
||||
|
||||
const handleStageAll = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (onStage) {
|
||||
onStage(filteredFiles.map(f => f.path))
|
||||
}
|
||||
}
|
||||
|
||||
const handleUnstageAll = (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (onUnstage) {
|
||||
onUnstage(filteredFiles.map(f => f.path))
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredFiles.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center justify-between px-2 py-1">
|
||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||
{staged ? 'Staged Changes' : 'Changes'} ({filteredFiles.length})
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-2 text-xs"
|
||||
onClick={staged ? handleUnstageAll : handleStageAll}
|
||||
>
|
||||
{staged ? (
|
||||
<>
|
||||
<Minus className="w-3 h-3 mr-1" />
|
||||
Unstage All
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
Stage All
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{groupedFiles.map(({ status, files: groupFiles }) => {
|
||||
const isCollapsed = collapsedGroups.has(status)
|
||||
|
||||
return (
|
||||
<div key={status}>
|
||||
<button
|
||||
className="flex items-center gap-1 px-2 py-1 w-full text-left hover:bg-accent rounded transition-colors"
|
||||
onClick={() => toggleGroup(status)}
|
||||
>
|
||||
{isCollapsed ? (
|
||||
<ChevronRight className="w-3 h-3 text-muted-foreground" />
|
||||
) : (
|
||||
<ChevronDown className="w-3 h-3 text-muted-foreground" />
|
||||
)}
|
||||
<span className={cn('text-xs font-medium', GIT_STATUS_COLORS[status])}>
|
||||
{GIT_STATUS_LABELS[status]}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
({groupFiles.length})
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{!isCollapsed && (
|
||||
<div className="ml-4">
|
||||
{groupFiles.map(file => (
|
||||
<GitFlatFileItem
|
||||
key={file.path}
|
||||
file={file}
|
||||
isSelected={selectedFile === file.path}
|
||||
onSelect={onSelect}
|
||||
onStage={handleStageFile}
|
||||
onUnstage={handleUnstageFile}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useGitStatus, getApiErrorMessage } from '@/api/git'
|
||||
import { listBranches, switchBranch } from '@/api/repos'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { ChangesTab } from './ChangesTab'
|
||||
import { CommitsTab } from './CommitsTab'
|
||||
import { BranchesTab } from './BranchesTab'
|
||||
import { FileDiffView } from '@/components/file-browser/FileDiffView'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
|
||||
import { GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
import {
|
||||
Loader2,
|
||||
GitBranch,
|
||||
FileCode,
|
||||
History,
|
||||
Upload,
|
||||
ArrowUp,
|
||||
ArrowDown,
|
||||
RefreshCw,
|
||||
ArrowDownFromLine,
|
||||
X,
|
||||
ChevronDown,
|
||||
Check,
|
||||
} from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
interface SourceControlPanelProps {
|
||||
repoId: number
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
currentBranch: string
|
||||
}
|
||||
|
||||
type Tab = 'changes' | 'commits' | 'branches'
|
||||
|
||||
export function SourceControlPanel({
|
||||
repoId,
|
||||
isOpen,
|
||||
onClose,
|
||||
currentBranch,
|
||||
}: SourceControlPanelProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('changes')
|
||||
const [selectedFile, setSelectedFile] = useState<{path: string, staged: boolean} | undefined>()
|
||||
const { data: status } = useGitStatus(repoId)
|
||||
const { data: branches } = useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
staleTime: 30000,
|
||||
})
|
||||
const git = useGit(repoId)
|
||||
const queryClient = useQueryClient()
|
||||
const isMobile = useMobile()
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: (updatedRepo) => {
|
||||
queryClient.setQueryData(['repo', repoId], updatedRepo)
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['gitStatus', repoId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['branches', repoId] })
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast.error(getApiErrorMessage(error))
|
||||
},
|
||||
})
|
||||
|
||||
const handleGitAction = async (action: () => Promise<unknown>) => {
|
||||
try {
|
||||
await action()
|
||||
} catch (error: unknown) {
|
||||
const message = getApiErrorMessage(error)
|
||||
showToast.error(message)
|
||||
}
|
||||
}
|
||||
|
||||
const tabs: { id: Tab; label: string; icon: React.ElementType }[] = [
|
||||
{ id: 'changes', label: 'Changes', icon: FileCode },
|
||||
{ id: 'commits', label: 'Commits', icon: History },
|
||||
{ id: 'branches', label: 'Branches', icon: GitBranch },
|
||||
]
|
||||
|
||||
const changesCount = status?.files.length || 0
|
||||
const stagedCount = status?.files.filter(f => f.staged).length || 0
|
||||
|
||||
const content = (
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="flex items-center justify-between px-3 py-2 border-b border-border flex-shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-2 hover:bg-accent rounded px-1 py-0.5 transition-colors">
|
||||
<GitBranch className="w-4 h-4 text-muted-foreground" />
|
||||
<span className="text-sm font-medium">{currentBranch}</span>
|
||||
<ChevronDown className="w-3 h-3 text-muted-foreground" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-48">
|
||||
{branches?.branches?.filter(b => b.type === 'local')?.map((branch) => (
|
||||
<DropdownMenuItem
|
||||
key={branch.name}
|
||||
onClick={() => branch.name !== currentBranch && switchBranchMutation.mutate(branch.name)}
|
||||
disabled={branch.name === currentBranch || switchBranchMutation.isPending}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<GitBranch className="w-4 h-4" />
|
||||
<span className="flex-1 truncate">{branch.name}</span>
|
||||
{branch.name === currentBranch && <Check className={`w-4 h-4 ${GIT_UI_COLORS.current}`} />}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{status && (status.ahead > 0 || status.behind > 0) && (
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
{status.ahead > 0 && (
|
||||
<span className={`flex items-center gap-0.5 ${GIT_UI_COLORS.ahead}`}>
|
||||
<ArrowUp className="w-3 h-3" />{status.ahead}
|
||||
</span>
|
||||
)}
|
||||
{status.behind > 0 && (
|
||||
<span className={`flex items-center gap-0.5 ${GIT_UI_COLORS.behind}`}>
|
||||
<ArrowDown className="w-3 h-3" />{status.behind}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleGitAction(() => git.fetch.mutateAsync())}
|
||||
disabled={git.fetch.isPending}
|
||||
className="h-7 w-7 p-0"
|
||||
title="Fetch from remote"
|
||||
>
|
||||
{git.fetch.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleGitAction(() => git.pull.mutateAsync())}
|
||||
disabled={git.pull.isPending}
|
||||
className="h-7 w-7 p-0"
|
||||
title="Pull"
|
||||
>
|
||||
{git.pull.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<ArrowDownFromLine className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleGitAction(() => git.push.mutateAsync(undefined))}
|
||||
disabled={git.push.isPending}
|
||||
className="h-7 w-7 p-0"
|
||||
title="Push"
|
||||
>
|
||||
{git.push.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<Upload className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex border-b border-border flex-shrink-0">
|
||||
{tabs.map((tab) => {
|
||||
const Icon = tab.icon
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 px-3 py-2 text-sm transition-colors border-b-2 -mb-px',
|
||||
activeTab === tab.id
|
||||
? 'border-primary text-foreground'
|
||||
: 'border-transparent text-muted-foreground hover:text-foreground hover:bg-accent'
|
||||
)}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
>
|
||||
<Icon className="w-4 h-4" />
|
||||
<span>{tab.label}</span>
|
||||
{tab.id === 'changes' && changesCount > 0 && (
|
||||
<span className="text-xs px-1.5 py-0.5 rounded-full bg-accent">
|
||||
{stagedCount > 0 ? `${stagedCount}/${changesCount}` : changesCount}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className={cn('flex-1 min-h-0', isMobile ? 'flex flex-col' : 'flex')}>
|
||||
<div className={cn(
|
||||
'overflow-hidden',
|
||||
isMobile ? 'flex-1' : selectedFile ? 'w-[35%] border-r border-border' : 'flex-1'
|
||||
)}>
|
||||
{activeTab === 'changes' && (
|
||||
<ChangesTab
|
||||
repoId={repoId}
|
||||
onFileSelect={(path, staged) => setSelectedFile({ path, staged })}
|
||||
selectedFile={selectedFile}
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'commits' && (
|
||||
<CommitsTab repoId={repoId} />
|
||||
)}
|
||||
{activeTab === 'branches' && (
|
||||
<BranchesTab repoId={repoId} currentBranch={currentBranch} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedFile && !isMobile && (
|
||||
<div className="flex-1 overflow-hidden flex flex-col">
|
||||
<div className="flex items-center justify-between px-3 py-2 border-b border-border">
|
||||
<span className="text-sm font-medium truncate">{selectedFile.path}</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 w-6 p-0"
|
||||
onClick={() => setSelectedFile(undefined)}
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-auto">
|
||||
<FileDiffView repoId={repoId} filePath={selectedFile.path} includeStaged={selectedFile.staged} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent
|
||||
mobileFullscreen
|
||||
hideCloseButton={isMobile}
|
||||
className={cn(
|
||||
'p-0 flex flex-col bg-card border-border',
|
||||
isMobile ? 'h-full' : 'w-[90vw] sm:max-w-6xl h-[90vh]'
|
||||
)}
|
||||
>
|
||||
<DialogHeader className={cn(
|
||||
'px-4 py-3 border-b border-border flex-shrink-0',
|
||||
isMobile && 'relative'
|
||||
)}>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<GitBranch className="w-5 h-5" />
|
||||
Source Control
|
||||
</DialogTitle>
|
||||
{isMobile && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onClose}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 h-10 w-10 p-0"
|
||||
>
|
||||
<X className="h-6 w-6" />
|
||||
</Button>
|
||||
)}
|
||||
</DialogHeader>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{content}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export { SourceControlPanel } from './SourceControlPanel'
|
||||
export { ChangesTab } from './ChangesTab'
|
||||
export { CommitsTab } from './CommitsTab'
|
||||
export { BranchesTab } from './BranchesTab'
|
||||
export { GitFlatFileList } from './GitFlatFileList'
|
||||
export { GitFlatFileItem } from './GitFlatFileItem'
|
||||
Reference in new issue
Block a user