This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 392
Test coverage for GitShellOutStrategy #1900
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a614905
Ignore conditionals that are too much of a pain to test
smashwilson 3b5e0b2
git rev-parse --resolve-git-dir will always return an absolute path
smashwilson 3313d22
"unfold" parameter is never used
smashwilson df55ac0
Cover throwing LargeRepoError from getStatusBundle()
smashwilson 3c2b06f
Cover codepaths in exec()
smashwilson 240ccdf
Cover fetchCommitMessageTemplate()
smashwilson 0b45487
Cover handling of unexpected git errors
smashwilson 24da545
Cover unexpected git diff output
smashwilson 97200a1
Input argument validation tests
smashwilson 8bf9385
Fail correctly when amending an unborn commit
smashwilson 4860e97
Test degenerate case of checkoutSide()
smashwilson 6539e2b
Cover git process spawn rejection
smashwilson f99e1e2
Use correct path separators in fake template paths
smashwilson 73a6354
Handle either path separator in EXPAND_TILDE_REGEX
smashwilson 3d34f7e
path.join() looks like it's resolving the path on Windows?
smashwilson efb6ddc
More Regexp tries
smashwilson 89be380
Grrr
smashwilson b346a45
Normalize commit template paths on Windows
smashwilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('^~([^\\\\/]*)[\\\\/]'); | ||
|
||
export default class GitShellOutStrategy { | ||
static defaultExecArgs = { | ||
|
@@ -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); | ||
|
@@ -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'; | ||
|
@@ -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}); | ||
|
@@ -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(); } | ||
}); | ||
}); | ||
|
@@ -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 ''; } | ||
|
@@ -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}`); | ||
|
@@ -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(); } | ||
}); | ||
}); | ||
|
@@ -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; | ||
} | ||
|
@@ -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); | ||
|
@@ -807,11 +816,8 @@ export default class GitShellOutStrategy { | |
} | ||
} | ||
|
||
mergeTrailers(commitMessage, trailers, unfold) { | ||
mergeTrailers(commitMessage, trailers) { | ||
const args = ['interpret-trailers']; | ||
if (unfold) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.)