From 17ffa48158d4647092bc0ed5aa00df99f2fa3f66 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Wed, 17 Sep 2025 22:19:12 +0100 Subject: [PATCH] fix: Fix SSH command escaping for version checking - Fix sed command escaping in git ls-remote command - Add explicit SSH key path and GIT_SSH_COMMAND environment - Add debug logging for troubleshooting SSH issues - Ensure proper SSH authentication for private repositories This resolves the 'Failed to fetch repository information' error when checking for updates from private GitHub repositories. --- backend/src/routes/versionRoutes.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/backend/src/routes/versionRoutes.js b/backend/src/routes/versionRoutes.js index 298cdd7..22bbd3a 100644 --- a/backend/src/routes/versionRoutes.js +++ b/backend/src/routes/versionRoutes.js @@ -63,12 +63,28 @@ router.get('/check-updates', authenticateToken, requireManageSettings, async (re const sshRepoUrl = `git@github.com:${owner}/${repo}.git`; try { - // Fetch the latest tag using SSH + // Set up environment for SSH + const sshKeyPath = process.env.HOME + '/.ssh/id_ed25519'; + const env = { + ...process.env, + GIT_SSH_COMMAND: `ssh -i ${sshKeyPath} -o StrictHostKeyChecking=no` + }; + + console.log('SSH Key Path:', sshKeyPath); + console.log('SSH Command:', env.GIT_SSH_COMMAND); + console.log('Repository URL:', sshRepoUrl); + + // Fetch the latest tag using SSH with explicit key const { stdout: latestTag } = await execAsync( - `git ls-remote --tags --sort=-version:refname ${sshRepoUrl} | head -n 1 | sed 's/.*refs\\/tags\\///' | sed 's/\\^\\{\\}//'`, - { timeout: 10000 } + `git ls-remote --tags --sort=-version:refname ${sshRepoUrl} | head -n 1 | sed 's/.*refs\\/tags\\///' | sed 's/\\^{}//'`, + { + timeout: 10000, + env: env + } ); + console.log('Latest tag output:', latestTag); + const latestVersion = latestTag.trim().replace('v', ''); // Remove 'v' prefix const currentVersion = '1.2.3'; @@ -80,7 +96,10 @@ router.get('/check-updates', authenticateToken, requireManageSettings, async (re try { const { stdout: tagDetails } = await execAsync( `git ls-remote --tags ${sshRepoUrl} | grep "${latestTag.trim()}" | head -n 1`, - { timeout: 5000 } + { + timeout: 5000, + env: env + } ); // Extract commit hash and other details if needed