* Asynchronously commits files using commitizen
(inquirer, repoPath, prompter, options, done)
| 21 | * Asynchronously commits files using commitizen |
| 22 | */ |
| 23 | function commit (inquirer, repoPath, prompter, options, done) { |
| 24 | var cacheDirectory = cacheDir('commitizen'); |
| 25 | var cachePath = path.join(cacheDirectory, 'commitizen.json'); |
| 26 | |
| 27 | ensureDir(cacheDirectory, function (error) { |
| 28 | if (error) { |
| 29 | console.error("Couldn't create commitizen cache directory: ", error); |
| 30 | // TODO: properly handle error? |
| 31 | } else { |
| 32 | if (options.retryLastCommit) { |
| 33 | |
| 34 | console.log('Retrying last commit attempt.'); |
| 35 | |
| 36 | // We want to use the last commit instead of the current commit, |
| 37 | // so lets override some options using the values from cache. |
| 38 | let { |
| 39 | options: retryOptions, |
| 40 | overrideOptions: retryOverrideOptions, |
| 41 | template: retryTemplate |
| 42 | } = cache.getCacheValueSync(cachePath, repoPath); |
| 43 | dispatchGitCommit(repoPath, retryTemplate, retryOptions, retryOverrideOptions, done); |
| 44 | |
| 45 | } else { |
| 46 | // Get user input -- side effect that is hard to test |
| 47 | prompter(inquirer, function (error, template, overrideOptions) { |
| 48 | // Allow adapters to error out |
| 49 | // (error: Error?, template: String, overrideOptions: Object) |
| 50 | if (!(error instanceof Error)) { |
| 51 | overrideOptions = template; |
| 52 | template = error; |
| 53 | error = null; |
| 54 | } |
| 55 | |
| 56 | if (error) { |
| 57 | return done(error); |
| 58 | } |
| 59 | |
| 60 | // We don't want to add retries to the cache, only actual commands |
| 61 | cache.setCacheValueSync(cachePath, repoPath, { template, options, overrideOptions }); |
| 62 | dispatchGitCommit(repoPath, template, options, overrideOptions, done); |
| 63 | }); |
| 64 | } |
| 65 | } |
| 66 | }); |
| 67 | |
| 68 | } |
no test coverage detected