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

Test coverage for GitShellOutStrategy #1900

Merged
merged 18 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const DISABLE_COLOR_FLAGS = [
* Ex: on Mac ~kuychaco/ is expanded to the specified user’s home directory (/Users/kuychaco)
* Regex translation:
* ^~ line starts with tilde
* ([^/]*)/ captures non-forwardslash characters before first slash
* ([^\\\\/]*)[\\\\/] captures non-slash characters before first slash
*/
const EXPAND_TILDE_REGEX = new RegExp('^~([^/]*)/');
const EXPAND_TILDE_REGEX = new RegExp('^~([^\\\\/]*)[\\\\/]');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's so much more...expandy! (I really wanted to come up with a better joke about this but couldn't.)


export default class GitShellOutStrategy {
static defaultExecArgs = {
Expand Down Expand Up @@ -119,6 +119,7 @@ export default class GitShellOutStrategy {
// Attempt to collect the --exec-path from a native git installation.
execPathPromise = new Promise((resolve, reject) => {
childProcess.exec('git --exec-path', (error, stdout, stderr) => {
/* istanbul ignore if */
if (error) {
// Oh well
resolve(null);
Expand Down Expand Up @@ -202,6 +203,7 @@ export default class GitShellOutStrategy {
env.ATOM_GITHUB_GPG_PROMPT = 'true';
}

/* istanbul ignore if */
if (diagnosticsEnabled) {
env.GIT_TRACE = 'true';
env.GIT_TRACE_CURL = 'true';
Expand All @@ -214,9 +216,11 @@ export default class GitShellOutStrategy {
opts.stdinEncoding = 'utf8';
}

/* istanbul ignore if */
if (process.env.PRINT_GIT_TIMES) {
console.time(`git:${formattedArgs}`);
}

return new Promise(async (resolve, reject) => {
if (options.beforeRun) {
const newArgsOpts = await options.beforeRun({args, opts});
Expand All @@ -236,6 +240,7 @@ export default class GitShellOutStrategy {
// chance to fall back to GIT_ASKPASS from the credential handler.
await new Promise((resolveKill, rejectKill) => {
require('tree-kill')(handlerPid, 'SIGTERM', err => {
/* istanbul ignore if */
if (err) { rejectKill(err); } else { resolveKill(); }
});
});
Expand All @@ -258,14 +263,18 @@ export default class GitShellOutStrategy {
timingMarker.mark('ipc', now - ipcTime);
}
timingMarker.finalize();

/* istanbul ignore if */
if (process.env.PRINT_GIT_TIMES) {
console.timeEnd(`git:${formattedArgs}`);
}

if (gitPromptServer) {
gitPromptServer.terminate();
}
subscriptions.dispose();

/* istanbul ignore if */
if (diagnosticsEnabled) {
const exposeControlCharacters = raw => {
if (!raw) { return ''; }
Expand Down Expand Up @@ -374,6 +383,7 @@ export default class GitShellOutStrategy {
options.processCallback = child => {
childPid = child.pid;

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

return new Promise((resolve, reject) => {
require('tree-kill')(childPid, 'SIGTERM', err => {
/* istanbul ignore if */
if (err) { reject(err); } else { resolve(); }
});
});
Expand All @@ -411,11 +423,7 @@ export default class GitShellOutStrategy {
await fs.stat(this.workingDir); // fails if folder doesn't exist
const output = await this.exec(['rev-parse', '--resolve-git-dir', path.join(this.workingDir, '.git')]);
const dotGitDir = output.trim();
if (path.isAbsolute(dotGitDir)) {
return toNativePathSep(dotGitDir);
} else {
return toNativePathSep(path.resolve(path.join(this.workingDir, dotGitDir)));
}
return toNativePathSep(dotGitDir);
} catch (e) {
return null;
}
Expand Down Expand Up @@ -446,6 +454,7 @@ export default class GitShellOutStrategy {
// if no user is specified, fall back to using the home directory.
return `${user ? path.join(path.dirname(homeDir), user) : homeDir}/`;
});
templatePath = toNativePathSep(templatePath);

if (!path.isAbsolute(templatePath)) {
templatePath = path.join(this.workingDir, templatePath);
Expand Down Expand Up @@ -807,11 +816,8 @@ export default class GitShellOutStrategy {
}
}

mergeTrailers(commitMessage, trailers, unfold) {
mergeTrailers(commitMessage, trailers) {
const args = ['interpret-trailers'];
if (unfold) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch on this unused param

args.push('--unfold');
}
for (const trailer of trailers) {
args.push('--trailer', `${trailer.token}=${trailer.value}`);
}
Expand Down
Loading