Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Prompt server updates to run under Electron 2.0 #1449

Merged
merged 9 commits into from
May 7, 2018
36 changes: 19 additions & 17 deletions bin/git-credential-atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async function fromKeytar(query) {

// Always remember credentials we had to go to GraphQL to get
await new Promise((resolve, reject) => {
fs.writeFile(rememberFile, err => {
fs.writeFile(rememberFile, '', {encoding: 'utf8'}, err => {
if (err) { reject(err); } else { resolve(); }
});
});
Expand Down Expand Up @@ -292,7 +292,7 @@ function dialog(query) {
log('requesting dialog through Atom socket');
log(`prompt = "${prompt}" includeUsername = ${includeUsername}`);

const socket = net.connect(sockPath, () => {
const socket = net.connect(sockPath, async () => {
log('connection established');

const parts = [];
Expand Down Expand Up @@ -320,7 +320,7 @@ function dialog(query) {
};

if (reply.remember) {
fs.writeFile(rememberFile, writeReply);
fs.writeFile(rememberFile, '', {encoding: 'utf8'}, writeReply);
} else {
writeReply();
}
Expand All @@ -331,7 +331,9 @@ function dialog(query) {
});

log('writing payload');
socket.write(JSON.stringify(payload) + '\u0000', 'utf8');
await new Promise(r => {
socket.write(JSON.stringify(payload) + '\u0000', 'utf8', r);
});
log('payload written');
});
socket.setEncoding('utf8');
Expand Down Expand Up @@ -426,17 +428,17 @@ log(`socket path = ${sockPath}`);
log(`action = ${action}`);

switch (action) {
case 'get':
get();
break;
case 'store':
store();
break;
case 'erase':
erase();
break;
default:
log(`Unrecognized command: ${action}`);
process.exit(0);
break;
case 'get':
get();
break;
case 'store':
store();
break;
case 'erase':
erase();
break;
default:
log(`Unrecognized command: ${action}`);
process.exit(0);
break;
}
37 changes: 32 additions & 5 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,18 @@ export default class GitShellOutStrategy {
// process does not terminate when the git process is killed.
// Kill the handler process *after* the git process has been killed to ensure that git doesn't have a
// chance to fall back to GIT_ASKPASS from the credential handler.
require('tree-kill')(handlerPid);
await new Promise((resolveKill, rejectKill) => {
require('tree-kill')(handlerPid, 'SIGTERM', err => {
if (err) { rejectKill(err); } else { resolveKill(); }
});
});
}));
}

const {stdout, stderr, exitCode, timing} = await promise.catch(err => {
const {stdout, stderr, exitCode, signal, timing} = await promise.catch(err => {
if (err.signal) {
return {signal: err.signal};
}
reject(err);
return {};
});
Expand All @@ -244,14 +251,20 @@ export default class GitShellOutStrategy {

if (diagnosticsEnabled) {
const exposeControlCharacters = raw => {
if (!raw) { return ''; }

return raw
.replace(/\u0000/ug, '<NUL>\n')
.replace(/\u001F/ug, '<SEP>');
};

if (headless) {
let summary = `git:${formattedArgs}\n`;
summary += `exit status: ${exitCode}\n`;
if (exitCode !== undefined) {
summary += `exit status: ${exitCode}\n`;
} else if (signal) {
summary += `exit signal: ${signal}\n`;
}
summary += 'stdout:';
if (stdout.length === 0) {
summary += ' <empty>\n';
Expand All @@ -270,7 +283,11 @@ export default class GitShellOutStrategy {
const headerStyle = 'font-weight: bold; color: blue;';

console.groupCollapsed(`git:${formattedArgs}`);
console.log('%cexit status%c %d', headerStyle, 'font-weight: normal; color: black;', exitCode);
if (exitCode !== undefined) {
console.log('%cexit status%c %d', headerStyle, 'font-weight: normal; color: black;', exitCode);
} else if (signal) {
console.log('%cexit signal%c %s', headerStyle, 'font-weight: normal; color: black;', signal);
}
console.log(
'%cfull arguments%c %s',
headerStyle, 'font-weight: normal; color: black;',
Expand Down Expand Up @@ -339,7 +356,17 @@ export default class GitShellOutStrategy {
marker && marker.mark('execute');
return {
promise,
cancel: () => childPid && require('tree-kill')(childPid),
cancel: () => {
if (!childPid) {
return Promise.resolve();
}

return new Promise((resolve, reject) => {
require('tree-kill')(childPid, 'SIGTERM', err => {
if (err) { reject(err); } else { resolve(); }
});
});
},
};
} else {
const workerManager = this.workerManager || WorkerManager.getInstance();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "github",
"main": "./lib/index",
"version": "0.14.0-1",
"version": "0.14.0-2",
"description": "GitHub integration",
"repository": "https://github.com/atom/github",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion test/git-prompt-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('GitPromptServer', function() {

afterEach(async function() {
if (this.currentTest.state === 'failed') {
if (stderrData.length > 0) {
if (stderrData.length > 0 || stdoutData.length > 0) {
/* eslint-disable no-console */
console.log(this.currentTest.fullTitle());
console.log(`STDERR:\n${stderrData.join('')}\n`);
Expand Down