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

Commit 337e620

Browse files
authored
Merge pull request #1900 from atom/aw/gsos-tests
Test coverage for GitShellOutStrategy
2 parents 6a29a88 + b346a45 commit 337e620

File tree

2 files changed

+212
-42
lines changed

2 files changed

+212
-42
lines changed

lib/git-shell-out-strategy.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const DISABLE_COLOR_FLAGS = [
6161
* Ex: on Mac ~kuychaco/ is expanded to the specified user’s home directory (/Users/kuychaco)
6262
* Regex translation:
6363
* ^~ line starts with tilde
64-
* ([^/]*)/ captures non-forwardslash characters before first slash
64+
* ([^\\\\/]*)[\\\\/] captures non-slash characters before first slash
6565
*/
66-
const EXPAND_TILDE_REGEX = new RegExp('^~([^/]*)/');
66+
const EXPAND_TILDE_REGEX = new RegExp('^~([^\\\\/]*)[\\\\/]');
6767

6868
export default class GitShellOutStrategy {
6969
static defaultExecArgs = {
@@ -119,6 +119,7 @@ export default class GitShellOutStrategy {
119119
// Attempt to collect the --exec-path from a native git installation.
120120
execPathPromise = new Promise((resolve, reject) => {
121121
childProcess.exec('git --exec-path', (error, stdout, stderr) => {
122+
/* istanbul ignore if */
122123
if (error) {
123124
// Oh well
124125
resolve(null);
@@ -202,6 +203,7 @@ export default class GitShellOutStrategy {
202203
env.ATOM_GITHUB_GPG_PROMPT = 'true';
203204
}
204205

206+
/* istanbul ignore if */
205207
if (diagnosticsEnabled) {
206208
env.GIT_TRACE = 'true';
207209
env.GIT_TRACE_CURL = 'true';
@@ -214,9 +216,11 @@ export default class GitShellOutStrategy {
214216
opts.stdinEncoding = 'utf8';
215217
}
216218

219+
/* istanbul ignore if */
217220
if (process.env.PRINT_GIT_TIMES) {
218221
console.time(`git:${formattedArgs}`);
219222
}
223+
220224
return new Promise(async (resolve, reject) => {
221225
if (options.beforeRun) {
222226
const newArgsOpts = await options.beforeRun({args, opts});
@@ -236,6 +240,7 @@ export default class GitShellOutStrategy {
236240
// chance to fall back to GIT_ASKPASS from the credential handler.
237241
await new Promise((resolveKill, rejectKill) => {
238242
require('tree-kill')(handlerPid, 'SIGTERM', err => {
243+
/* istanbul ignore if */
239244
if (err) { rejectKill(err); } else { resolveKill(); }
240245
});
241246
});
@@ -258,14 +263,18 @@ export default class GitShellOutStrategy {
258263
timingMarker.mark('ipc', now - ipcTime);
259264
}
260265
timingMarker.finalize();
266+
267+
/* istanbul ignore if */
261268
if (process.env.PRINT_GIT_TIMES) {
262269
console.timeEnd(`git:${formattedArgs}`);
263270
}
271+
264272
if (gitPromptServer) {
265273
gitPromptServer.terminate();
266274
}
267275
subscriptions.dispose();
268276

277+
/* istanbul ignore if */
269278
if (diagnosticsEnabled) {
270279
const exposeControlCharacters = raw => {
271280
if (!raw) { return ''; }
@@ -374,6 +383,7 @@ export default class GitShellOutStrategy {
374383
options.processCallback = child => {
375384
childPid = child.pid;
376385

386+
/* istanbul ignore next */
377387
child.stdin.on('error', err => {
378388
throw new Error(
379389
`Error writing to stdin: git ${args.join(' ')} in ${this.workingDir}\n${options.stdin}\n${err}`);
@@ -385,12 +395,14 @@ export default class GitShellOutStrategy {
385395
return {
386396
promise,
387397
cancel: () => {
398+
/* istanbul ignore if */
388399
if (!childPid) {
389400
return Promise.resolve();
390401
}
391402

392403
return new Promise((resolve, reject) => {
393404
require('tree-kill')(childPid, 'SIGTERM', err => {
405+
/* istanbul ignore if */
394406
if (err) { reject(err); } else { resolve(); }
395407
});
396408
});
@@ -411,11 +423,7 @@ export default class GitShellOutStrategy {
411423
await fs.stat(this.workingDir); // fails if folder doesn't exist
412424
const output = await this.exec(['rev-parse', '--resolve-git-dir', path.join(this.workingDir, '.git')]);
413425
const dotGitDir = output.trim();
414-
if (path.isAbsolute(dotGitDir)) {
415-
return toNativePathSep(dotGitDir);
416-
} else {
417-
return toNativePathSep(path.resolve(path.join(this.workingDir, dotGitDir)));
418-
}
426+
return toNativePathSep(dotGitDir);
419427
} catch (e) {
420428
return null;
421429
}
@@ -446,6 +454,7 @@ export default class GitShellOutStrategy {
446454
// if no user is specified, fall back to using the home directory.
447455
return `${user ? path.join(path.dirname(homeDir), user) : homeDir}/`;
448456
});
457+
templatePath = toNativePathSep(templatePath);
449458

450459
if (!path.isAbsolute(templatePath)) {
451460
templatePath = path.join(this.workingDir, templatePath);
@@ -807,11 +816,8 @@ export default class GitShellOutStrategy {
807816
}
808817
}
809818

810-
mergeTrailers(commitMessage, trailers, unfold) {
819+
mergeTrailers(commitMessage, trailers) {
811820
const args = ['interpret-trailers'];
812-
if (unfold) {
813-
args.push('--unfold');
814-
}
815821
for (const trailer of trailers) {
816822
args.push('--trailer', `${trailer.token}=${trailer.value}`);
817823
}

0 commit comments

Comments
 (0)