Replace URL token embedding with GIT_ASKPASS for git authentication

This commit is contained in:
Chris Scott committed 2025-12-05 07:51:33 -08:00
1 parent daf5754cc1
commit e37059360a
3 files changed
+5 -10

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ function getGitEnvironment(database: Database): Record<string, string> {
if (gitToken) {
return {
GITHUB_TOKEN: gitToken,
GIT_ASKPASS: 'echo',
GIT_ASKPASS: 'echo $GITHUB_TOKEN',
GIT_TERMINAL_PROMPT: '0'
}
}
@@ -99,7 +99,7 @@ class OpenCodeServerManager {
XDG_DATA_HOME: path.join(OPENCODE_SERVER_DIRECTORY, '.opencode/state'),
OPENCODE_CONFIG: OPENCODE_CONFIG_PATH,
GITHUB_TOKEN: gitToken,
GIT_ASKPASS: 'echo',
GIT_ASKPASS: gitToken ? 'echo $GITHUB_TOKEN' : 'echo',
GIT_TERMINAL_PROMPT: '0'
}
}
+3 -8
View File
@@ -17,12 +17,7 @@ async function hasCommits(repoPath: string): Promise<boolean> {
}
}
function getAuthenticatedUrl(repoUrl: string, gitToken: string): string {
if (gitToken && repoUrl.startsWith('https://github.com')) {
return repoUrl.replace('https://', `https://${gitToken}@`)
}
return repoUrl
}
async function safeGetCurrentBranch(repoPath: string): Promise<string | null> {
try {
@@ -88,7 +83,7 @@ export async function initLocalRepo(
const env: Record<string, string> = gitToken ?
{
GITHUB_TOKEN: gitToken,
GIT_ASKPASS: 'echo',
GIT_ASKPASS: 'echo $GITHUB_TOKEN',
GIT_TERMINAL_PROMPT: '0'
} :
{ GIT_ASKPASS: 'echo', GIT_TERMINAL_PROMPT: '0' }
@@ -176,7 +171,7 @@ export async function cloneRepo(
const settings = settingsService.getSettings('default')
const gitToken = settings.preferences.gitToken
const cloneUrl = getAuthenticatedUrl(repoUrl, gitToken || '')
const cloneUrl = repoUrl
if (shouldUseWorktree) {
logger.info(`Creating worktree for branch: ${branch}`)