get-edit-file-path.js 1.1 KB

1234567891011121314151617181920212223242526
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.getEditFilePath = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const fs_extra_1 = __importDefault(require("fs-extra"));
  9. // Get path to recently edited commit message file
  10. async function getEditFilePath(top, edit) {
  11. if (typeof edit === 'string') {
  12. return path_1.default.resolve(top, edit);
  13. }
  14. const dotgitPath = path_1.default.join(top, '.git');
  15. const dotgitStats = await fs_extra_1.default.lstat(dotgitPath);
  16. if (dotgitStats.isDirectory()) {
  17. return path_1.default.join(top, '.git/COMMIT_EDITMSG');
  18. }
  19. const gitFile = await fs_extra_1.default.readFile(dotgitPath, {
  20. encoding: 'utf-8',
  21. });
  22. const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', '');
  23. return path_1.default.resolve(top, relativeGitPath, 'COMMIT_EDITMSG');
  24. }
  25. exports.getEditFilePath = getEditFilePath;
  26. //# sourceMappingURL=get-edit-file-path.js.map