git.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.setIonicRemote = exports.addIonicRemote = exports.getIonicRemote = exports.initializeRepo = exports.isRepoInitialized = exports.getTopLevel = exports.isGitInstalled = void 0;
  4. const tslib_1 = require("tslib");
  5. const utils_fs_1 = require("@ionic/utils-fs");
  6. const path = tslib_1.__importStar(require("path"));
  7. async function isGitInstalled({ shell }) {
  8. return Boolean(await shell.cmdinfo('git', ['--version']));
  9. }
  10. exports.isGitInstalled = isGitInstalled;
  11. async function getTopLevel({ shell }) {
  12. return shell.cmdinfo('git', ['rev-parse', '--show-toplevel']);
  13. }
  14. exports.getTopLevel = getTopLevel;
  15. async function isRepoInitialized(dir) {
  16. return (0, utils_fs_1.pathExists)(path.join(dir, '.git'));
  17. }
  18. exports.isRepoInitialized = isRepoInitialized;
  19. async function initializeRepo({ shell }, dir) {
  20. await shell.run('git', ['init'], { cwd: dir });
  21. }
  22. exports.initializeRepo = initializeRepo;
  23. async function getIonicRemote({ shell }, dir) {
  24. const regex = /ionic\t(.+) \(\w+\)/;
  25. // would like to use get-url, but not available in git 2.0.0
  26. const remotes = await shell.output('git', ['remote', '-v'], { cwd: dir });
  27. for (const line of remotes.split('\n')) {
  28. const match = regex.exec(line.trim());
  29. if (match) {
  30. return match[1];
  31. }
  32. }
  33. }
  34. exports.getIonicRemote = getIonicRemote;
  35. async function addIonicRemote({ shell }, dir, url) {
  36. await shell.run('git', ['remote', 'add', 'ionic', url], { cwd: dir });
  37. }
  38. exports.addIonicRemote = addIonicRemote;
  39. async function setIonicRemote({ shell }, dir, url) {
  40. await shell.run('git', ['remote', 'set-url', 'ionic', url], { cwd: dir });
  41. }
  42. exports.setIonicRemote = setIonicRemote;