Error: Cannot use simple-git on a directory that does not exist
I am trying to checkout a new repo using https://www.npmjs.com/package/simple-git, so obviously that folder does not exist yet.
Following is the full exception trace
2019-08-21T07:44:55.979641+00:00 app[web.1]: (node:23) UnhandledPromiseRejectionWarning: Error: Cannot use simple-git on a directory that does not exist.
2019-08-21T07:44:55.979644+00:00 app[web.1]: at module.exports (/app/node_modules/simple-git/src/index.js:9:14)
2019-08-21T07:44:55.979645+00:00 app[web.1]: at Object.<anonymous> (/app/server/services/gitService.js:14:40)
2019-08-21T07:44:55.979647+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-08-21T07:44:55.979649+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-08-21T07:44:55.979650+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-08-21T07:44:55.979652+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-08-21T07:44:55.979653+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-08-21T07:44:55.979655+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-08-21T07:44:55.979657+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-08-21T07:44:55.979658+00:00 app[web.1]: at Object.<anonymous> (/app/server/services/dbService.js:13:20)
2019-08-21T07:44:55.979754+00:00 app[web.1]: (node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
1 Answer
5 years ago by VD
simple-git
needs a working directory for all operations, you can ensure the given directory exists using mkdirp
library.
var mkdirp = require('mkdirp');
var repoPath = '/path/to/repo';
mkdirp.sync(repoPath);
The above code creates /path/to/repo
folder if not already exists.
5 years ago by Karthik Divi