Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d22966

Browse files
authored
Merge pull request atom#1449 from atom/aw/electron-2.0-updates
Prompt server updates to run under Electron 2.0
2 parents 9aa3715 + 1fe7344 commit 2d22966

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

bin/git-credential-atom.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async function fromKeytar(query) {
257257

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

295-
const socket = net.connect(sockPath, () => {
295+
const socket = net.connect(sockPath, async () => {
296296
log('connection established');
297297

298298
const parts = [];
@@ -320,7 +320,7 @@ function dialog(query) {
320320
};
321321

322322
if (reply.remember) {
323-
fs.writeFile(rememberFile, writeReply);
323+
fs.writeFile(rememberFile, '', {encoding: 'utf8'}, writeReply);
324324
} else {
325325
writeReply();
326326
}
@@ -331,7 +331,9 @@ function dialog(query) {
331331
});
332332

333333
log('writing payload');
334-
socket.write(JSON.stringify(payload) + '\u0000', 'utf8');
334+
await new Promise(r => {
335+
socket.write(JSON.stringify(payload) + '\u0000', 'utf8', r);
336+
});
335337
log('payload written');
336338
});
337339
socket.setEncoding('utf8');
@@ -426,17 +428,17 @@ log(`socket path = ${sockPath}`);
426428
log(`action = ${action}`);
427429

428430
switch (action) {
429-
case 'get':
430-
get();
431-
break;
432-
case 'store':
433-
store();
434-
break;
435-
case 'erase':
436-
erase();
437-
break;
438-
default:
439-
log(`Unrecognized command: ${action}`);
440-
process.exit(0);
441-
break;
431+
case 'get':
432+
get();
433+
break;
434+
case 'store':
435+
store();
436+
break;
437+
case 'erase':
438+
erase();
439+
break;
440+
default:
441+
log(`Unrecognized command: ${action}`);
442+
process.exit(0);
443+
break;
442444
}

lib/git-shell-out-strategy.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,18 @@ export default class GitShellOutStrategy {
217217
// process does not terminate when the git process is killed.
218218
// Kill the handler process *after* the git process has been killed to ensure that git doesn't have a
219219
// chance to fall back to GIT_ASKPASS from the credential handler.
220-
require('tree-kill')(handlerPid);
220+
await new Promise((resolveKill, rejectKill) => {
221+
require('tree-kill')(handlerPid, 'SIGTERM', err => {
222+
if (err) { rejectKill(err); } else { resolveKill(); }
223+
});
224+
});
221225
}));
222226
}
223227

224-
const {stdout, stderr, exitCode, timing} = await promise.catch(err => {
228+
const {stdout, stderr, exitCode, signal, timing} = await promise.catch(err => {
229+
if (err.signal) {
230+
return {signal: err.signal};
231+
}
225232
reject(err);
226233
return {};
227234
});
@@ -244,14 +251,20 @@ export default class GitShellOutStrategy {
244251

245252
if (diagnosticsEnabled) {
246253
const exposeControlCharacters = raw => {
254+
if (!raw) { return ''; }
255+
247256
return raw
248257
.replace(/\u0000/ug, '<NUL>\n')
249258
.replace(/\u001F/ug, '<SEP>');
250259
};
251260

252261
if (headless) {
253262
let summary = `git:${formattedArgs}\n`;
254-
summary += `exit status: ${exitCode}\n`;
263+
if (exitCode !== undefined) {
264+
summary += `exit status: ${exitCode}\n`;
265+
} else if (signal) {
266+
summary += `exit signal: ${signal}\n`;
267+
}
255268
summary += 'stdout:';
256269
if (stdout.length === 0) {
257270
summary += ' <empty>\n';
@@ -270,7 +283,11 @@ export default class GitShellOutStrategy {
270283
const headerStyle = 'font-weight: bold; color: blue;';
271284

272285
console.groupCollapsed(`git:${formattedArgs}`);
273-
console.log('%cexit status%c %d', headerStyle, 'font-weight: normal; color: black;', exitCode);
286+
if (exitCode !== undefined) {
287+
console.log('%cexit status%c %d', headerStyle, 'font-weight: normal; color: black;', exitCode);
288+
} else if (signal) {
289+
console.log('%cexit signal%c %s', headerStyle, 'font-weight: normal; color: black;', signal);
290+
}
274291
console.log(
275292
'%cfull arguments%c %s',
276293
headerStyle, 'font-weight: normal; color: black;',
@@ -339,7 +356,17 @@ export default class GitShellOutStrategy {
339356
marker && marker.mark('execute');
340357
return {
341358
promise,
342-
cancel: () => childPid && require('tree-kill')(childPid),
359+
cancel: () => {
360+
if (!childPid) {
361+
return Promise.resolve();
362+
}
363+
364+
return new Promise((resolve, reject) => {
365+
require('tree-kill')(childPid, 'SIGTERM', err => {
366+
if (err) { reject(err); } else { resolve(); }
367+
});
368+
});
369+
},
343370
};
344371
} else {
345372
const workerManager = this.workerManager || WorkerManager.getInstance();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "github",
33
"main": "./lib/index",
4-
"version": "0.14.0-1",
4+
"version": "0.14.0-2",
55
"description": "GitHub integration",
66
"repository": "https://github.com/atom/github",
77
"license": "MIT",

test/git-prompt-server.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('GitPromptServer', function() {
5959

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

0 commit comments

Comments
 (0)