Add git password input (for now)

This commit is contained in:
Alex Gleason committed 2025-09-12 18:03:48 -05:00
1 parent 227b0fab76
commit ddf09c6684
1 file changed
+77
+77
View File
@@ -17,6 +17,8 @@ import {
} from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
GitBranch,
Upload,
@@ -30,6 +32,8 @@ import {
Minus,
Edit,
RefreshCw,
Eye,
EyeOff,
} from 'lucide-react';
import { useGitStatus } from '@/hooks/useGitStatus';
import { useFS } from '@/hooks/useFS';
@@ -50,6 +54,9 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
const [isPulling, setIsPulling] = useState(false);
const [pushResult, setPushResult] = useState<string | null>(null);
const [pullResult, setPullResult] = useState<string | null>(null);
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
const { fs } = useFS();
@@ -91,6 +98,11 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
try {
const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin')
// Prepare authentication if username and password are provided
const authOptions = username && password ? {
onAuth: () => ({ username, password }),
} : {};
await git.push({
fs,
http,
@@ -98,6 +110,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
remote: remote.name,
ref: gitStatus.currentBranch,
corsProxy: 'https://cors.isomorphic-git.org',
...authOptions,
});
setPushResult(`✅ Successfully pushed ${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} to ${remote.name}/${gitStatus.currentBranch}`);
@@ -146,6 +159,11 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
try {
const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin')
// Prepare authentication if username and password are provided
const authOptions = username && password ? {
onAuth: () => ({ username, password }),
} : {};
await git.pull({
fs,
http,
@@ -157,6 +175,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
name: 'shakespeare.diy',
email: '[email protected]',
},
...authOptions,
});
setPullResult(`✅ Successfully pulled from ${remote.name}/${gitStatus.currentBranch}`);
@@ -338,6 +357,64 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
</CardContent>
</Card>
{/* Authentication */}
{gitStatus?.isGitRepo && gitStatus.remotes.length > 0 && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Authentication</CardTitle>
<CardDescription>
Enter credentials for push/pull operations (optional)
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 gap-4">
<div className="space-y-2">
<Label htmlFor="git-username">Username</Label>
<Input
id="git-username"
type="text"
placeholder="Git username"
value={username}
onChange={(e) => setUsername(e.target.value)}
disabled={isPushing || isPulling}
/>
</div>
<div className="space-y-2">
<Label htmlFor="git-password">Password / Token</Label>
<div className="relative">
<Input
id="git-password"
type={showPassword ? "text" : "password"}
placeholder="Git password or personal access token"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={isPushing || isPulling}
className="pr-10"
/>
<Button
type="button"
variant="ghost"
size="sm"
className="absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent"
onClick={() => setShowPassword(!showPassword)}
disabled={isPushing || isPulling}
>
{showPassword ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</Button>
</div>
</div>
</div>
<div className="text-xs text-muted-foreground">
Leave empty for public repositories or if using SSH keys. For private repositories, use your username and personal access token.
</div>
</CardContent>
</Card>
)}
{/* Sync Status */}
{gitStatus?.isGitRepo && (
<Card>