Hey,
I discoverd that the bin/credentials-helper ignores the --rootPath, because the request url http://localhost:${port}/api/credentials in the credentials-helper#L14 is without the rootPath.
Test-Case
Run the ungit command with the --rootPath like:
&> ungit --rootPath=/ungit --port=4000
Open http://localhost:4000/ungit/ and try to clone a repository. The clone operation fails with the followring response:
{
"isGitError":true,
"errorCode":"unknown",
"command":"-c color.ui=false -c core.quotepath=false -c core.pager=cat -c credential.helper=/usr/lib/node_modules/ungit/bin/credentials-helper 0 4000 https://github.com/FredrikNoren/ungit.git clone https://github.com/FredrikNoren/ungit.git ungit",
"workingDirectory":"/home",
"error":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n at JSON.parse (<anonymous>)\n at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n at emitOne (events.js:116:13)\n at IncomingMessage.emit (events.js:211:7)\n at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n at flow (_stream_readable.js:846:34)\n at resume_ (_stream_readable.js:828:3)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n",
"message":"Cloning into 'ungit'...",
"stderr":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n at JSON.parse (<anonymous>)\n at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n at emitOne (events.js:116:13)\n at IncomingMessage.emit (events.js:211:7)\n at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n at flow (_stream_readable.js:846:34)\n at resume_ (_stream_readable.js:828:3)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n",
"stdout":""
}
Solution
Just pass the rootPath to the bin/credentials-helper, like socketId or origin.
My-Quick-Fix
I add a environment variable ROOT_PATH to the url for the bin/credentials-helper.
Example:
let localUrl = `api/credentials?socketId=${socketId}&remote=${encodeURIComponent(remote)}`;
if (process.env['ROOT_PATH']) {
localUrl = url.resolve(process.env['ROOT_PATH'], localUrl);
}
localUrl = url.resolve(`http://localhost:${port}`, localUrl);
// ...
http.get(localUrl, (res) => {
// ...
Hey,
I discoverd that the
bin/credentials-helperignores the--rootPath, because the request urlhttp://localhost:${port}/api/credentialsin the credentials-helper#L14 is without therootPath.Test-Case
Run the
ungitcommand with the--rootPathlike:Open http://localhost:4000/ungit/ and try to clone a repository. The clone operation fails with the followring response:
{ "isGitError":true, "errorCode":"unknown", "command":"-c color.ui=false -c core.quotepath=false -c core.pager=cat -c credential.helper=/usr/lib/node_modules/ungit/bin/credentials-helper 0 4000 https://github.com/FredrikNoren/ungit.git clone https://github.com/FredrikNoren/ungit.git ungit", "workingDirectory":"/home", "error":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n at JSON.parse (<anonymous>)\n at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n at emitOne (events.js:116:13)\n at IncomingMessage.emit (events.js:211:7)\n at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n at flow (_stream_readable.js:846:34)\n at resume_ (_stream_readable.js:828:3)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n", "message":"Cloning into 'ungit'...", "stderr":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n at JSON.parse (<anonymous>)\n at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n at emitOne (events.js:116:13)\n at IncomingMessage.emit (events.js:211:7)\n at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n at flow (_stream_readable.js:846:34)\n at resume_ (_stream_readable.js:828:3)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n", "stdout":"" }Solution
Just pass the
rootPathto thebin/credentials-helper, likesocketIdororigin.My-Quick-Fix
I add a environment variable
ROOT_PATHto the url for thebin/credentials-helper.Example: