feat: add repository git credential fixer

This commit is contained in:
Agent committed 2026-10-18 10:55:21 +00:00
1 parent 25cea75eb5
commit c6e042db86
7 files changed
+120 -10

No files matched your search

+17 -2
View File
@@ -4,8 +4,7 @@
import os from 'node:os'
import path from 'node:path'
import {
ForgeError, api, apiList, cloneRepo, deriveName, gitIn, listAccounts, listRepos,
normRepo, publicAccount, pushRepo, resolveRepo,
ForgeError, api, apiList, cloneRepo, deriveName, fixRepoConfig, gitIn, listAccounts, listRepos, normRepo, publicAccount, pushRepo, resolveRepo,
} from './forge.mjs'
import {
accountsWithStatus, cliStatus, giteaLogin, githubDeviceCancel, githubDeviceStart, githubDeviceStatus,
@@ -348,6 +347,15 @@ async function toolPush(args, exec) {
return pushRepo({ cwd, remote: args.remote, branch: args.branch, force: !!args.force, tags: !!args.tags, signal: exec?.signal })
}
async function toolFixCredentials(args, exec) {
const cwd = sessionCwd(exec)
const requested = String(args.path ?? '').trim()
const repoPath = requested
? path.resolve(cwd, requested.replace(/^~(?=\/|$)/, os.homedir()))
: cwd
return fixRepoConfig(repoPath)
}
// ---- tool definitions ---------------------------------------------------------
const S = (type, description, extra = {}) => ({ type, description, ...extra })
@@ -482,6 +490,13 @@ const TOOLS = [
},
required: ['path'],
}, toolApi),
defineTool({
name: 'forge_fix_credentials',
description: 'Fix the local git credential helper configuration inside a repository. Replaces only that repository’s .git/config credential.helper values with the git-forge helper, so plain git fetch, pull, and push can authenticate through authorized GitHub and Gitea accounts. Does not change global git configuration.',
properties: {
path: S('string', 'Repository directory (default: the session working directory). Relative paths use the session working directory; a nested path resolves to its repository root.'),
},
}, toolFixCredentials),
]
// ---- plugin -----------------------------------------------------------------