* Fix git credential saving and improve host matching

- Fix token masking bug in GitCredentialDialog that corrupted tokens on edit
- Add tokenEdited state to preserve original token when not modified
- Default new credential host to https://github.com
- Add normalizeHostname helper for consistent host comparison
- Improve credential lookup logging to show configured vs requested hosts
- Remove overly permissive fuzzy matching that could leak tokens

* Make OpenCode reload non-fatal when saving git credentials

Settings are now saved to database even if the OpenCode server reload
fails. The reload error is returned separately so the UI can inform
the user that credentials were saved but the server needs a manual
restart.

* Fix git fetch using credentials in silent mode

Previously, silent mode (used for UI fetch operations) would skip
credential lookup entirely and return empty, causing auth failures.
Now credentials are always looked up via IPC regardless of silent mode.
This commit is contained in:
Chris Scott authored and GitHub committed 2026-01-25 00:38:47 -05:00
1 parent 3a8d4993c1
commit 24aa4f6c83
6 files changed
+80 -39

No files matched your search

@@ -22,22 +22,24 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
token: '',
username: '',
})
const [tokenEdited, setTokenEdited] = useState(false)
const maskToken = (token: string) => {
if (!token) return ''
if (token.length <= 8) return '•'.repeat(token.length)
return token.slice(0, 8) + '...'
return token.slice(0, 4) + '•'.repeat(Math.min(token.length - 4, 12)) + '...'
}
useEffect(() => {
if (open) {
setTokenEdited(false)
if (credential) {
setFormData({
...credential,
token: maskToken(credential.token)
token: ''
})
} else {
setFormData({ name: '', host: '', token: '', username: '' })
setFormData({ name: '', host: 'https://github.com', token: '', username: '' })
}
}
}, [open, credential])
@@ -46,13 +48,20 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
event?.preventDefault()
event?.stopPropagation()
if (!formData.name.trim() || !formData.host.trim() || !formData.token.trim()) {
const isEditing = !!credential
const tokenRequired = isEditing ? tokenEdited : true
if (!formData.name.trim() || !formData.host.trim() || (tokenRequired && !formData.token.trim())) {
showToast.error('Please fill in all required fields')
return
}
try {
await onSave(formData)
const dataToSave: GitCredential = {
...formData,
token: (isEditing && !tokenEdited) ? credential.token : formData.token
}
await onSave(dataToSave)
setFormData({ name: '', host: '', token: '', username: '' })
onOpenChange(false)
} catch {
@@ -91,15 +100,25 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
</div>
<div className="space-y-2">
<Label htmlFor="cred-token">Access Token *</Label>
<Label htmlFor="cred-token">
Access Token {credential && !tokenEdited ? '(unchanged)' : '*'}
</Label>
<Input
id="cred-token"
type="password"
placeholder="Personal access token"
placeholder={credential ? maskToken(credential.token) : 'Personal access token'}
value={formData.token}
onChange={(e) => setFormData({ ...formData, token: e.target.value })}
onChange={(e) => {
setTokenEdited(true)
setFormData({ ...formData, token: e.target.value })
}}
disabled={isSaving}
/>
{credential && !tokenEdited && (
<p className="text-xs text-muted-foreground">
Leave empty to keep existing token
</p>
)}
</div>
<div className="space-y-2">
@@ -124,7 +143,7 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
</Button>
<Button
type="submit"
disabled={isSaving || !formData.name.trim() || !formData.host.trim() || !formData.token.trim()}
disabled={isSaving || !formData.name.trim() || !formData.host.trim() || (!credential && !formData.token.trim())}
>
{isSaving && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
{credential ? 'Update' : 'Add'}
@@ -75,9 +75,13 @@ export function GitSettings() {
setIsSaving(true)
try {
showToast.loading('Saving git configuration...', { id: 'git-config' })
await updateSettingsAsync({ gitCredentials, gitIdentity })
const result = await updateSettingsAsync({ gitCredentials, gitIdentity })
setHasChanges(false)
showToast.success('Git configuration saved', { id: 'git-config' })
if (result.reloadError) {
showToast.success('Git configuration saved (server reload pending)', { id: 'git-config' })
} else {
showToast.success('Git configuration saved', { id: 'git-config' })
}
} catch {
showToast.error('Failed to save git configuration', { id: 'git-config' })
} finally {