git.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _path() {
  7. const data = _interopRequireDefault(require('path'));
  8. _path = function _path() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _execa() {
  14. const data = _interopRequireDefault(require('execa'));
  15. _execa = function _execa() {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _interopRequireDefault(obj) {
  21. return obj && obj.__esModule ? obj : {default: obj};
  22. }
  23. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  24. try {
  25. var info = gen[key](arg);
  26. var value = info.value;
  27. } catch (error) {
  28. reject(error);
  29. return;
  30. }
  31. if (info.done) {
  32. resolve(value);
  33. } else {
  34. Promise.resolve(value).then(_next, _throw);
  35. }
  36. }
  37. function _asyncToGenerator(fn) {
  38. return function() {
  39. var self = this,
  40. args = arguments;
  41. return new Promise(function(resolve, reject) {
  42. var gen = fn.apply(self, args);
  43. function _next(value) {
  44. asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
  45. }
  46. function _throw(err) {
  47. asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
  48. }
  49. _next(undefined);
  50. });
  51. };
  52. }
  53. const findChangedFilesUsingCommand =
  54. /*#__PURE__*/
  55. (function() {
  56. var _ref = _asyncToGenerator(function*(args, cwd) {
  57. const result = yield (0, _execa().default)('git', args, {
  58. cwd
  59. });
  60. return result.stdout
  61. .split('\n')
  62. .filter(s => s !== '')
  63. .map(changedPath => _path().default.resolve(cwd, changedPath));
  64. });
  65. return function findChangedFilesUsingCommand(_x, _x2) {
  66. return _ref.apply(this, arguments);
  67. };
  68. })();
  69. const adapter = {
  70. findChangedFiles: (function() {
  71. var _findChangedFiles = _asyncToGenerator(function*(cwd, options) {
  72. const changedSince =
  73. options && (options.withAncestor ? 'HEAD^' : options.changedSince);
  74. const includePaths = ((options && options.includePaths) || []).map(
  75. absoluteRoot =>
  76. _path().default.normalize(_path().default.relative(cwd, absoluteRoot))
  77. );
  78. if (options && options.lastCommit) {
  79. return findChangedFilesUsingCommand(
  80. ['show', '--name-only', '--pretty=format:', 'HEAD'].concat(
  81. includePaths
  82. ),
  83. cwd
  84. );
  85. } else if (changedSince) {
  86. const committed = yield findChangedFilesUsingCommand(
  87. [
  88. 'log',
  89. '--name-only',
  90. '--pretty=format:',
  91. 'HEAD',
  92. `^${changedSince}`
  93. ].concat(includePaths),
  94. cwd
  95. );
  96. const staged = yield findChangedFilesUsingCommand(
  97. ['diff', '--cached', '--name-only'].concat(includePaths),
  98. cwd
  99. );
  100. const unstaged = yield findChangedFilesUsingCommand(
  101. ['ls-files', '--other', '--modified', '--exclude-standard'].concat(
  102. includePaths
  103. ),
  104. cwd
  105. );
  106. return [...committed, ...staged, ...unstaged];
  107. } else {
  108. return findChangedFilesUsingCommand(
  109. ['ls-files', '--other', '--modified', '--exclude-standard'].concat(
  110. includePaths
  111. ),
  112. cwd
  113. );
  114. }
  115. });
  116. function findChangedFiles(_x3, _x4) {
  117. return _findChangedFiles.apply(this, arguments);
  118. }
  119. return findChangedFiles;
  120. })(),
  121. getRoot: (function() {
  122. var _getRoot = _asyncToGenerator(function*(cwd) {
  123. const options = ['rev-parse', '--show-cdup'];
  124. try {
  125. const result = yield (0, _execa().default)('git', options, {
  126. cwd
  127. });
  128. return _path().default.resolve(cwd, result.stdout);
  129. } catch (e) {
  130. return null;
  131. }
  132. });
  133. function getRoot(_x5) {
  134. return _getRoot.apply(this, arguments);
  135. }
  136. return getRoot;
  137. })()
  138. };
  139. var _default = adapter;
  140. exports.default = _default;